Finding working area size in android

You must Login before you can answer or comment on any questions.

Hi there,

I've read all the posts that try to solve this issue with android, but i can't get the size of the working area of the window with any of them.

Most of the posts are based on the 'open' event of the window, but that doesn't work.

This is the code i'm trying:

var mywindow = Ti.UI.createWindow({
    });
 
    var viewToCalculateSize = Ti.UI.createView({
    });
 
    mywindow.add(viewToCalculateSize);
 
    mywindow.addEventListener('open', function(){
    alert('window height: ' + viewToCalculateSize.size.height);
    alert('window width: ' + viewToCalculateSize.size.width);
    });
 
    mywindow.addEventListener('click', function(){
    alert('window height: ' + viewToCalculateSize.size.height);
    alert('window width: ' + viewToCalculateSize.size.width);
    });
 
    mywindow.open();
The results for this code are 0 values for the 'open' event. That means the view or window is not created yet when the open event triggers. Is there any event that triggers when the window is completely loaded?

The results for the 'click' event are correct, but obviously i can't use that event to retrieve the window size values.

Any other option?

Thanks in advance.

— asked 7 months ago by Kowaks Kowalinsky
3 Comments
  • http://docs.appcelerator.com/titanium/2.1/index.html#!/api/Titanium.UI.View-property-size

    — commented 7 months ago by Muhammad Adnan

  • You'll notice he's already using the size property. The key is the postlayout event, like I mentioned.

    — commented 7 months ago by Jason Priebe

  • yes you are right, i want to show that it is documented that using size will give 0 values of height and width ,The correct values will only be available when layout is complete( add a postlayout event)

    — commented 7 months ago by Muhammad Adnan

2 Answers

if you want to know the size of a full window then you can get this with Ti.Platform.DisplayCaps.platformWidth and Ti.Platform.DisplayCaps.platformHeight.

Your Answer

Think you can help? Login to answer this question!