Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7336] Android: Size.height and size.width are always 0 for Labels created after window is opened

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2012-06-06T11:48:30.000+0000
Affected Version/sRelease 1.8.0.1
Fix Version/sn/a
ComponentsAndroid
Labelsapi
ReporterJustin Toth
AssigneeNeeraj Gupta
Created2012-01-23T10:04:28.000+0000
Updated2017-03-24T18:17:43.000+0000

Description

Using Ti 1.8.0.1 with Android and V8, Labels always have their size.height and size.width properties set to 0. They obviously can't be calculated before the window is open, but after it is and the labels are drawn these properties should be set correctly. Here is code to reproduce:
var win = Ti.UI.createWindow({ backgroundColor: "#fff" });
win.addEventListener("open", function() { 
	
	//create labels.
	var label1 = Ti.UI.createLabel({ text: "label 1 with height auto", color: "#000", top: 0, left: 0, height: "auto" });
	win.add(label1);
	
	var label2 = Ti.UI.createLabel({ text: "label 2 with width set and height auto", color: "#000", top: 50, left: 0, width: 250, height: "auto" });
	win.add(label2);
	
	var label3 = Ti.UI.createLabel({ text: "label 3 with width and height set", color: "#000", top: 100, left: 0, width: 250, height: 30 });
	win.add(label3);
	
	//output label heights.
	Ti.API.info("label 1 height: " + label1.size.height);
	Ti.API.info("label 2 height: " + label2.size.height);
	Ti.API.info("label 3 height: " + label3.size.height);

});
win.open();
Results: android 2.2 emulator (V8): label 1 height: 0, label 2 height: 0, label 3 height: 0 <--incorrect droid x2 w/android 2.3.4 (V8): label 1 height: 0, label 2 height: 0, label 3 height: 0 0 <--incorrect iphone simulator: label 1 height: 22, label 2 height: 42, label 3 height: 30 <--correct

Comments

  1. Paul Dowsett 2012-01-26

    Possible duplicate of TIMOB-5303. Mauro to investigate.
  2. Ping Wang 2012-06-06

    When the "open" event is fired, the layout is not finished yet. Therefore the size.height and size.width for labels are not correctly calculated at that time. Maybe you want to try the event "postlayout" which is fired when the layout is finished. The attached test case behaves as expected.
  3. Justin Toth 2012-06-06

    As you can see, this bug was from long before the 2.0 release and the "postlayout" event.
  4. Lee Morris 2017-03-24

    Closing ticket as invalid with reference to the above comments.

JSON Source