Layout.xml with two layout ids

Help!
For the same specific watch (lets assume 920) - I would like to describe two different layouts that would be initiated after a "App.getApp().getProperty" code.

As i'm doing the initial watch layout @ Layout.xml, i was wondering to setup those two layouts (that uses different images) - but they just ovelap and load all of them in sequence!

<resources>
<layout id="WatchFace">
<bitmap id="logo" x="center" y="20" filename="../IMAGE1" />
</layout id>

<layout id="WatchFaceB">
<bitmap id="logo" x="center" y"20" filename="../IMAGE2" />
</layout id>
</resources>




function onLayout(dc)
{
if ( Property == 0 )
{
setLayout(Rez.Layouts.WatchFace(dc));
}
else
{
setLayout(Rez.Layouts.WatchFaceB(dc));
}
}


Any ideias why this approach is not working?
Best regards,
  • I believe that once inside the view, you cannot use the setLayout after the onLayout has been called.
    That is why I have moved the logic into my AppBase class which controls "restarting" the watchface by instantiating a new view and switching to it. This way it forces the onLayout to be called.

    I think setLayout is sensitive to the lifecycle of a view and only works when called in onLayout.
    Because of this belief I was looking at the "restart" mechanism as explained above.
    There seem to be no impact on memory as far as I can see.


    Just saying that this theory is incorrect. It actually only works in the simulator (which is a bug) and not on real devices (by design).
    The issue with the simulator has been reported.
  • Former Member
    Former Member over 9 years ago
    If you just want to switch the image, why do you change the whole layout?

    You can do the following:

    <drawables>
    <bitmap id="img1" filename="IMAGE1.png" />
    <bitmap id="img2" filename="IMAGE2.png" />
    </drawables>


    And in your code:

    var img = View.findDrawableById("logo");

    if (Property == 0) {
    img.setBitmap(Rez.Drawables.img1);
    }
    else {
    img.setBitmap(Rez.Drawables.img2);
    }
  • 1526

    If you just want to switch the image, why do you change the whole layout?

    You can do the following:

    <drawables>
    <bitmap id="img1" filename="IMAGE1.png" />
    <bitmap id="img2" filename="IMAGE2.png" />
    </drawables>


    And in your code:

    var img = View.findDrawableById("logo");

    if (Property == 0) {
    img.setBitmap(Rez.Drawables.img1);
    }
    else {
    img.setBitmap(Rez.Drawables.img2);
    }


    Should i read

    var img = "View.findDrawableById("img1");


    or maybe i'm missing something again....

    i'm quiting the setlayout stuff, because it simply does not work - and i'll need to write from scratch by now...
  • Should i read

    var img = "View.findDrawableById("img1");


    or maybe i'm missing something again....

    i'm quiting the setlayout stuff, because it simply does not work - and i'll need to write from scratch by now...


    You are welcome to send me your project so I can help you out. Got mine to work.
  • Former Member
    Former Member over 9 years ago
    Should i read

    var img = "View.findDrawableById("img1");


    or maybe i'm missing something again....

    i'm quiting the setlayout stuff, because it simply does not work - and i'll need to write from scratch by now...


    No, the ID of your bitmap object was logo:

    <resources>
    <layout id="WatchFace">
    <bitmap id="logo" x="center" y="20" filename="../IMAGE1" />
    </layout id>
    </resources>


    So in your code you can get that bitmap object:

    var img = View.findElementById("logo");


    Then you can replace the image of the bitmap object:

    img.setBitmap(<qualifier for image>);


    To do so, you need to have a qualifier (Rez.drawables.<qualifier>) for your images:

    <bitmap id="img1" filename="IMAGE1.png" />
  • No, the ID of your bitmap object was logo:


    TeunMo! It worked using the "setbitmap"!!
    Many thanks for the replies!!!!

    Best regards!
  • I've been sitting on this problem too. Solution:

    TeunMo's example in this thread works but you have to change the bitmap ID's. Otherwise the bitmaps will draw over each other.

    I hope this will help someone else having issues since I know this thread is quite old.