Drawables on layout.xml

Former Member
Former Member

Hello. 

I'm creating my first watch face. It is going to be very static and I can define almost everything beforehand. I have labels defined and I wanted to define some icons in layout.xml. 

I have defined some bitmaps on resources.xml and when I tried to reference them from layout.xml as a drawable I got an error saying that x property (for position) is not supported by drawable. According to developer guide I'd, x and Y are valid props for drawable, so what I'm doing wrong? 

  • It might help if you posted your code so we could try it ourselves and point out the errors.

    You should be able to generate a sample watch-app from the project templates, and it demonstrates how to place a bitmap in a layout:

    <layout id="MainLayout">
        <label x="center" y="5" text="@Strings.prompt" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_CENTER" />
        <bitmap id="id_monkey" x="center" y="30" filename="../drawables/monkey.png" />
    </layout>

    I haven't tried to do this in a while, but you should be able to use a custom drawable for this as well. Something like:

    <layout id="MainLayout">
        <label x="center" y="5" text="@Strings.prompt" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_CENTER" />
        <drawable id="id_monkey" class="WatchUi.Bitmap">
            <param name="locX">center</param>
            <param name="locY">30</param>
            <param name="rezId">@Drawables.myBitmap</param>
        </drawable>
    </layout>

  • Former Member
    Former Member over 5 years ago in reply to Travis.ConnectIQ

    Hello ,

    Thanks for your response.

    Your first snippet is what I ended doing. However, by reading the documentation I came to the conclusion that the following was possible:

    In resources/drawables.xml:

    <drawables>
        <bitmap id="LauncherIcon" filename="launcher_icon.png" />
        <bitmap id="batteryMask" filename="battery_mask.png"/>
    </drawables>

    Then just reference the bitmap on the layout like this:

    <layout>
       <drawable id="batteryMask" x="5" y="70"/>
    </layout>
    

    However that does not work at all. I came to this conclusion by reading the following on developer docs:

    https://developer.garmin.com/connect-iq/programmers-guide/user-interface#drawables

    Drawables (both bitmaps and drawable XML resources) can also be included in a layout using the drawable tag. The following attributes are supported by the drawable tag:

    Regards

  • However that does not work at all. I came to this conclusion by reading the following on developer doc

    Ugh. Looks like a docs bug. I'm pretty sure you need to create a drawable-list with positioning information, and then reference that drawable list in the layout.

  • Former Member
    Former Member over 5 years ago in reply to Travis.ConnectIQ

    Yes, it definetively looks like a documentation bug. Is there anyone we can warn about it? 

  • @Travis.ConnectIQ This is *still* a bug in the docs.