Layout Background Help

Hi,

I'm just getting my feet wet. Initially I'm trying to make some simple changes to a watchface using the layout system and am not seeing the changes I expect.

I tried modifying the layout xml file to specify a background color and it does not appear to change. If I am reading the User Interface guide correct, I should be able to set the background property and I would expect the background to actually change.

<layout id="WatchFace" background="Gfx.COLOR_WHITE">
<label id="TimeLabel" x="center" y="center" font="Gfx.FONT_LARGE" justification="Gfx.TEXT_JUSTIFY_CENTER" color="Gfx.COLOR_WHITE" />
</layout>


In the simulator I still see a black background.



I can change the text color and see that change so I'm pretty sure I'm changing the right file and the layout is set correctly etc. Am I misunderstanding the background feature of the layout?

I'm sure I'm doing something silly and once I see a working example I'll see how easy it is... but for the moment, not so much. I can clear it manually using setColor and clear on the DrawingContext, but I figured it would be part of the layout.

As I'm writing this and thinking about it, maybe in the example, that is what the Mainbackground drawable is, just a rectangle the size of the screen "clearing the view"?

Secondly, I see references to the resource compiler being smart about laying out out for various devices. Is there a way of controlling positioning in the resource/layout files that isn't absolute positioning? I can set the x and y of a bitmap, but I have to know what device I'm targetting if I want that centered for example.

Maybe these are all answered somewhere and I'm missing the magic documentation link.

Thanks,

Ben
  • I have seen the same problem. Unfortunately, I never got around to reporting it...
  • I've been able to replicate this. I'll check into it and get it reported.
  • Former Member
    Former Member over 10 years ago
    I have a simular but different problem with background.
    In the programmers guide it says that the default color of a shape is "Current draw context’s foreground color."

    I have a layout:

    <layout id="MainLayout">
    <drawable id="background" />
    </layout>


    <drawable-list id="background">
    <shape id="MainBackground" type="rectangle"/>
    </drawable-list>


    And in code:
    dc.setColor(Gfx.COLOR_RED, Gfx.COLOR_RED);
    View.setLayout(Rez.Layouts.MainLayout(dc));
    View.onUpdate(dc);


    With this I would have expected the background of my data field to turn red, but it does not.
    If I give my shape a color attribute, that works fine. I can't however retreive the shape with View.findDrawableById("MainBackground") to change it.
  • Thanks for the feedback folks.

    I also answered a few of my own questions I think.

    I'm getting a better understanding of "overriding resource files". I think that is part of my answer for how to handle different models.

    The other part is realizing that the x field has a valid value of "center". I noticed it in the text field for the time and tried it with a bitmap and it worked. The documentation only states that it is a pixel value but obviously there are more options. It would be nice if the documentation was updated to reflect all of the options available.