Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-6911] Android: Parent View's size.height (and width) will return '0' when set to auto. (Parity issue)

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionInvalid
Resolution Date2012-02-10T00:10:35.000+0000
Affected Version/sRelease 1.8.0.1
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterMauro Parra-Miranda
AssigneeMarshall Culpepper
Created2011-12-28T14:50:01.000+0000
Updated2012-02-10T00:10:35.000+0000

Description

PROBLEM DESCRIPTION

You have a parent view with height and width set to 'auto'. When you add views to this parent view, you eventually can ask for the current width and height, via the "size" dictionary. In iOS, it's working just fine, you add a child view, and the parent view will get you the right height. That is not working on Android.

STEPS TO REPRODUCE

1. Create a mobile project 2. Paste the code below to the app.js 3. Run in Android.

CODE

var win = Ti.UI.createWindow();
var view = Ti.UI.createView({
	height:'auto',
	width:'auto'
});

var otherview=Ti.UI.createView({
	backgroundColor:'white',
	width:100,
	height:100,
});

view.add(otherview);
win.add(view);
Ti.API.info("View height:");
Ti.API.info(view.size.height);
win.open();

Comments

  1. Ivan Skugor 2011-12-29

    On Android, dimensions are calculated when window opens, so to get dimensions of some component, you must use window's "open" event.
       view.add(otherview);
       win.add(view);
       win.addEventListener('open', function() {
           Ti.API.info("View height:");
           Ti.API.info(view.size.height);
       }
       win.open();
       
    I'm not sure is this ticket a request for a change of Android's dimension calculation functionality, but I certainly think that this is an issue on Android side.
  2. Marshall Culpepper 2012-01-03

    As Ivan points out, We cannot know the view's dimensions before the view is draw on screen (which is what happens when win.open() is called). You'd either need to do this in an open event, or some other time after the view has shown.

JSON Source