Failure to use Ti.UI.currentWindow.height while building a ui on android

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

hi I'm trying to build a simple scenario, 3 views in a vertical layout. one on the top one on the bottom (both are 50 pixels) and the middle view which will occupy the rest of the screen.

var mainView = Ti.UI.createView({
        layout:'vertical',
        top:0,
        left:0
    });
    var adView = Ti.UI.createView({
        height:150,
        backgroundColor:'#FF00FF'
    });
    bottomView = Ti.UI.createView({
        height:50,
        backgroundColor:'#00FF00'
    });
    mapview = Titanium.Map.createView({
        mapType: Titanium.Map.SATELLITE_TYPE,
        animate:true,
        regionFit:true,
        userLocation:true,
        height: Ti.UI.currentWindow.height - bottomView.height - adView.height
 
    });
 
    Titanium.API.error("**************** height "+Ti.UI.currentWindow.height);
 
    mainView.add(adView);
    mainView.add(mapview);
    mainView.add(bottomView);
Ti.UI.currentWindow.height is showing the right values on IOS but 0 on android. Any ideas on how to achieve the desired result?

2 Answers

Have you tried height:'auto'? If that doesn't work, then the answer is Ti.Platform.displayCaps.platformHeight-150-50 (since your code showed height:150 for the adView and height:50 for the bottomView).

— answered 3 years ago by Shawn Lipscomb
answer permalink
2 Comments
  • ...or to be complete:

    height: Ti.UI.Platform.displayCaps.platformHeight - bottomView.height - adView.height

    — commented 3 years ago by Shawn Lipscomb

  • Hi Shawn, auto == 0 when the view is in the middle so it's not good . Ti.UI.Platform.displayCaps.platformHeight is the size of the whole screen which includes the status bar and such. what is missing is a way to know the current container view size before it is rendered.

    — commented 3 years ago by Yosi Taguri

Use the size property of the view. height should be the value set on it as a layout parameter. When the layout parity work is finished both iOS and Android will not update the layout properties like height, width, etc.

Your Answer

Think you can help? Login to answer this question!