Same position with different screen sizes

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

Hello, sorry for my english i'm french. In my app i have different elements but theire position are not the same with different screen size. For example:

var webview2 = Ti.UI.createWebView({
    url:'myurl',
    touchEnabled:false,
    height:220,
    bottom:300,
});
In a 480x800 screen, this webview is in the good positions visualy but in a 720x1280 screen it's not in the same (and good) positions

Help me please. Thanks.

— asked 10 months ago by Philip Lasserre
1 Comment
  • Philip,

    Try specifying the values as dp.

    height:'220dp',
    bottom:'300dp'

    — commented 10 months ago by Brian Jackson

3 Answers

Accepted Answer

Hi Philip

There is another way you can achieve this if you are using SDK 2.0 or higher.

If you want to leave a specific amount of space underneath another view (map in this case) you can use the new Ti.UI.FILL parameter and set another value.

This example would create a map view filling the screen height BUT leave a gap of 50dp gap at the bottom, you do not need to calculate anything.

var webview2 = Ti.UI.createWebView({
    url:'myurl',
    touchEnabled:false,
    height:Ti.UI.FILL,
    bottom: '50dp'  // change this to whatever value you require
});
You can also adjust the top as well as the bottom at the same time, this would create a map that would fill the screen BUT leave a gap at the top of 150dp and one at the bottom of 50dp. So the map would use the remaining space. This will work on any device height automatically.
var webview2 = Ti.UI.createWebView({
    url:'myurl',
    touchEnabled:false,
    height:Ti.UI.FILL,
    bottom: '50dp',  // change this to whatever value you require
    top: '150dp'  // change this to whatever value you require
});
BTW the layout property will only affect child windows you add to the map, so you can leave it out of the construction of the mapview.

Philip,

Try specifying the values as dp.

height:'220dp',
bottom:'300dp'

Thanks Brian but I have found an other less solution but it's work. My solution :

var hauteur = (Titanium.Platform.displayCaps.platformHeight-220)/2;
 
var webview2 = Ti.UI.createWebView({
    url:'myurl',
    touchEnabled:false,
    height:220,
    bottom:hauteur,
    layout:"vertical",
});

Your Answer

Think you can help? Login to answer this question!