问题
For Android
I have two labels in a table row. I am trying to set these two label vertical but the firstLabel
overlaps the second one. As firstLabel
's height is "auto" and it contains dynamic text e.g. 10 lines , 20 line.
Due to dynamic height of firstLabel
I couldn't set secondLabel
's top so it gets overlapped.
I've tried all possible solution available on the SO and Appcelerator but couldn't find the fix.
1). I couldn't get height of firstLabel
after or before adding it to the view, table's row etc...
2) Tried to set height of label according to text's length but couldn't fix it .
Still looking for the solution..

回答1:
What you'll need to do is not to set the layout to vertical on the label, but rather on the view that is containing all the labels. If the parent view has a vertical layout, it will place the second label immediately after the first label ends. Additionally, setting the "top" property of the second label will place that many units between the bottom of label1 and top of label 2. Think relative positioning of block elements in CSS.
回答2:
Solved... According to DannyM 's answer . I also notice that, adding order of label into the row also matters.
for (var i = 0; i < results.length; i++)
{
// Create a row and set its height to auto
row = Titanium.UI.createTableViewRow
({
height:'auto',
layout :'vertical'
});
var currentObj = results[i];
// Create the label to hold the place name
var placeNameLabel = Titanium.UI.createLabel
({
text:currentObj.PlaceName,
left:'75dp',
top:'auto',
width:'auto',
height:'18dp',
textAlign:'left',
font:{fontSize:'14dp',fontWeight:'bold'},
wordWrap:true
});
var placeAddressLabel = Titanium.UI.createLabel
({
text:currentObj.PlaceAddress,
left:'75dp',
top:'auto',
width:'230dp',
height:'auto',
textAlign:'left',
font:{fontSize:'14dp'}
});
var checkInDate = Titanium.UI.createLabel
({
text:currentObj.CheckInDate+' '+currentObj.CheckInTime,
left:'75dp',
top:'auto', //placeAddressLabel.height + 30 +'dp',
width:'165dp',
height:'25dp',
textAlign:'left',
font:{fontSize:'14dp'},
wordWrap:true,
});
row.add(placeNameLabel);
row.add(placeAddressLabel);
row.add(checkInDate)
tableData[i] = row;
}
return tableData ;
来源:https://stackoverflow.com/questions/9738397/titanium-label-over-lapping-issue