Search code examples
javascriptandroidtitaniumappceleratortitanium-alloy

how to use postlayout in titanium (Alloy )imageview


Example code using postlayout in Titanium 3.x (Alloy) :

View:

 <Alloy>
    <Window class="container">
        <Label id="testLabel" onClick="doClick">Hello, World</Label>
        <ImageView id="testImgView" autoStyle="true" ></ImageView>
    </Window>
</Alloy>

Controller:

 $.testLabel.addEventListener('postlayout', function(e) {
        Ti.API.info('Label postlayout working!');
    });
     $.testImgView.image='default.png';
     $.testImgView.addEventListener('postlayout', function(e) {
        Ti.API.info('Img postlayout working!');
    });
     $.index.open();

Result:

[INFO][TiAPI   ( 2188)]  Label postlayout working!

Solution

  • you are right, I've just tried your code on Android and it won't work with version 3.1.3GA. It must be a Bug.

    If it's not an inconvenient for you you can use

    <View id="testImgView" autoStyle="true" ></View>
    

    and

    $.testImgView.backgroundImage='/default.png';
    

    And it will work

    Or you can create an Issue here

    Edit

    I've tried on iPhone Simulator SDK 6.1 and it fires imageView postlayout events well