Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24388] Android: 'center' property for Label does not work well on Android

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionInvalid
Resolution Date2017-02-10T13:55:34.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsipass1
ReporterShuo Liang
AssigneeGary Mathews
Created2017-02-09T02:24:34.000+0000
Updated2017-03-28T20:19:18.000+0000

Description

Reproduce

1. Run the following code on Both iOS and Android devices
var OS_IOS = (Ti.Platform.name === 'iPhone OS');

var locationBlockWindow = Ti.UI.createWindow({
	backgroundColor:"#E6ffffff"
});

var transView = Ti.UI.createView({
	top:Ti.Platform.displayCaps.platformHeight/(OS_IOS ? 3 : 6),
	bottom:Ti.Platform.displayCaps.platformHeight/(OS_IOS ? 3 : 6),
	left:40,
	right:40,
	layout:"vertical",
	width:Ti.UI.FILL,
	height:Ti.UI.FILL,
	backgroundColor:"#80E7832B",
	borderRadius: 5
});

var labelTxt = Ti.UI.createLabel({
	font: { fontSize:'18dp' },
	text: 'IAS Dispatch app is disabled while driving for your safety. Please use the app when vehicle is not in motion.',
	textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
	center: {
		x:0,
		//y:100
		y:Ti.Platform.displayCaps.platformHeight/(OS_IOS ? 6 : 24),
	},
	width: Ti.UI.SIZE,
	height: Ti.UI.SIZE,
	left: 10,
	right: 10,
});
 
transView.add(labelTxt);
locationBlockWindow.add(transView);
locationBlockWindow.open();

Ti.API.info('Top: ' + transView.getTop());
Ti.API.info('Center: ' + labelTxt.getCenter().y);

Problem

In labelTxt the:
center: {
		x:0,
		y:Ti.Platform.displayCaps.platformHeight/(OS_IOS ? 6 : 24),
},
works in iOS but in Android. The "Ti.API.info('Center: ' + labelTxt.getCenter().y);" returns a valid number but we see no impact on the positioning of the label on Android.

Attachments

FileDateSize
test.png2017-02-10T13:54:52.000+000029505

Comments

  1. Gary Mathews 2017-02-10

    [~sliang] Firstly, in the example given both top and bottom are set to the same value, making the view invisible. Secondly, center will not work on components added to a view with a layout type defined.
       var win = Ti.UI.createWindow(),
           view = Ti.UI.createView({
               //top: Ti.Platform.displayCaps.platformHeight/6,
               //bottom: Ti.Platform.displayCaps.platformHeight/6,
               left: 40,
               right: 40,
               //layout: 'vertical',
               width: Ti.UI.FILL,
               height: Ti.UI.FILL,
               backgroundColor: 'red',
               borderRadius: 5
           }),
           lbl = Ti.UI.createLabel({
               font: {
                   fontSize: '18dp'
               },
               text: 'IAS Dispatch app is disabled while driving for your safety. Please use the app when vehicle is not in motion.',
               textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
               center: {
                   x: 0,
                   y: Ti.Platform.displayCaps.platformHeight/24
               },
               width: Ti.UI.SIZE,
               height: Ti.UI.SIZE,
               left: 10,
               right: 10
           });
       
       view.add(lbl);
       win.add(view);
       
    !test.png|thumbnail!
  2. Shuo Liang 2017-02-22

    [~gmathews] Please confirm the last comment.
  3. Gary Mathews 2017-02-22

    [~sliang] Correct, I'm not sure why you would define the exact position of a View if you're using a layout to determine the positioning?
  4. Eric Merriman 2017-03-28

    Closing as invalid. Please reopen if you disagree [~sliang]

JSON Source