Label w auto height disappears
I'm building a grouped table view from a database table. Each row has a pair of labels with height set to auto on each as well as the row. When I use the size.height property of the label it causes them to randomly disappear. Also if you click on that row sometimes the label then displays.
var row = Titanium.UI.createTableViewRow({
height:'auto',
selectedBackgroundColor:'transparent'
});
var rowLabel1 = Ti.UI.createLabel({
text:'Section: ' + s + ', Row: ' + r,
color:'#576996',
font:{fontSize:14,fontWeight:'bold'},
top:rowPadding,
height:'auto',
width: 300 - (rowPadding * 2),
left:rowPadding
});
row.add(rowLabel1);
var rowLabel2 = Ti.UI.createLabel({
text:"Other textnAnother line of text",
font:{fontSize:14},
top:rowLabel1.size.height + rowPadding,
height:'auto',
left:rowLabel1.left,
width:rowLabel1.width
});
row.add(rowLabel2);
var textHeight = rowLabel1.size.height + rowLabel2.size.height;
row.height = textHeight + (rowPadding * 2);
I tried remove the .size.height calls and removing the formatting by reducing it to just one label. All the labels show up correctly now, but sometimes the spacing is off, especially after scrolling.
for (var s=1;s<5;s++) {
for (var r=1;r<10;r++) {
var row = Titanium.UI.createTableViewRow({
height:'auto',
selectedBackgroundColor:'transparent'
});
var title = 'Section: ' + s + ', ';
if (s%2==0) title = title + "n";
title = title + 'Row: ' + r;
var rowLabel1 = Ti.UI.createLabel({
text:title + "nOther textnAnother line of text",
color:'#576996',
font:{fontSize:14,fontWeight:'bold'},
top:rowPadding,
height:'auto',
bottom:rowPadding,
right:rowPadding,
left:rowPadding
});
row.add(rowLabel1);
if (r==1) {
row.header = 'Section: ' + s;
}
data.push(row);
}
}
3 Answers
-
I'm having the exact same issue with disappearing labels on a
View
. I've gotten around the issue by creating a "dummy" label first to get the height and then creating the "real" label with a fixed height:var label = Titanium.UI.createLabel({ text: description, width:100, height:'auto', top:10, left:10 }); var label2 = Titanium.UI.createLabel({ text: description, width:100, height:label.size.height, top:10, left:10 }); view.add(label2);
Not ideal, I know - but it seems to keep the labels visible.
-
label.size.height is working only for iphone and its not working for android
-
Hello,
i have the same problem can you help me to fix it?
do you have any solution?thanks,
Eliza