繁体   English   中英

钛:标签重叠问题

[英]Titanium : Label over lapping issue

对于Android

我在表格行中有两个标签。 我试图将这两个标签设置为垂直,但是firstLabel与第二个标签重叠。 由于firstLabel的高度为“ 自动 ”,因此包含动态文本,例如10行,20行。

由于firstLabel动态高度,我无法设置secondLabel的顶部,因此会重叠。

我已经尝试了SO和Appcelerator上所有可用的解决方案,但找不到解决方法。

1)。 在将它添加到视图,表的行等之前或之后,我无法获取firstLabel高度...

2)尝试根据文本的长度设置标签的高度,但无法修复。

仍在寻找解决方案。

在此处输入图片说明

您要做的不是在标签上将布局设置为垂直,而是在包含所有标签的视图上将布局设置为垂直。 如果父视图具有垂直布局,它将在第一个标签结束后立即放置第二个标签。 此外,设置第二个标签的“ top”属性会将许多单位放置在label1的底部和标签2的顶部之间。考虑一下CSS中块元素的相对位置。

解决了...根据DannyM的回答。 我还注意到,将标签的顺序添加到行中也很重要。

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 ;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM