Layouts with drawables, bitmaps and text - That's all? I need dynamic subviews

Former Member
Former Member
Still cannot figure out how to add reusable elements to a layout , e.g. a heart rate history or battery status indicator. The current elements in a layout XML are all static, or simple selectables. How would I go about implementing dynamic, structured subviews?
  • As I said before, maybe look at a few open sourced things (there's a sticky here with PeterD's page) and see how others do it in CIQ.

    I can understand your frustration, but also understand there are thousands of apps in the store that have things similar to what you are trying to do, and there is a bit of a learning curve.
  • That exactly what I wanted to avoid. The whole idea of subviews (or: custom drawables) is their local coordinate system, so you can place them anywhere without changing code.

    I found that I could use the <drawable id="mySubviewId" class="MyModule.MyClassName"> tag, but then there's no way to add x, y, width and height, as the DTD doesn't allow that. So how am I supposed to place these drawables in the view?



    You can do that. Here is sample code.

    In your layout:

    <layout id="Layout">
    <label id="datetLabel" x="center" y="11" font="Gfx.FONT_SMALL" justification="Gfx.TEXT_JUSTIFY_CENTER" />
    <drawable class="Clock">
    <param name="locX">118</param>
    <param name="locY">114</param>
    <param name="color">Gfx.COLOR_WHITE</param>
    </drawable>
    </layout>


    In your drawable Clock.mc

    class Clock extends Ui.Drawable {
    var Color;

    function initialize(dictionary) {
    dictionary.put(:identifier, "Clock");
    Drawable.initialize(dictionary);
    Color = dictionary[:Color;
    }

    function draw(dc) {
    dc.setColor(Color, Color);
    dc.drawText(locX, locY, Gfx.FONT_SMALL, "12:00", Gfx.TEXT_JUSTIFY_CENTER);
    }
    }


    Note that locX and locY by default is available within your class.
    For arbitrary parameters you have to add them to the dictionary in your initialize method.
  • Former Member
    Former Member
    Thanks for the XML layout hints. I'll check that out. Hope it also works for width and height parameters.

    Yes, IQ has a learning curve. I'm now at 3 apps and 2 barrels. I'm used to coding 3,000+ classes projects. Definitely not a newbie to software engineering and language design. I now ended up implementing a TranslatedDeviceContext that does the offsetting and clipping. It's not pretty, because that translated DC needs to be setup manually, but it keeps me going for now.

    I suggest Garmin fix DeviceContext for translation & clipping natively, though.