【问题标题】:Titanium : Label over lapping issue钛:标签重叠问题
【发布时间】:2023-03-09 14:04:01
【问题描述】:

安卓版

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

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

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

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

2) 尝试set height of label according to text's length,但无法修复。

仍在寻找解决方案..

【问题讨论】:

    标签: android titanium appcelerator titanium-mobile


    【解决方案1】:

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

    【讨论】:

    • 为了增加您在获取动态视图时遇到的问题,所有设备都有不同的分辨率和密度,因此应用程序在显示在屏幕上之前不知道高度是多少。这样就可以在给窗口添加标签并打开窗口后得到高度值了。
    • 你知道的人..我试图从过去 2 天解决它!我对android的布局结构一无所知......非常感谢你的帮助......非常感谢它的工作......
    • 还有一件事...我需要进行哪些修改才能将图像视图设置为水平,即左侧有空白区域?
    • 我认为图像视图会将图像拉伸到视图的大小,但我不是 100% 确定。
    • 实际上,如果我放置图像视图,那么我的第一个标签将放在图像视图之后。假设图像视图的高度为 50,那么第一个标签将自动从 52 开始...
    【解决方案2】:

    已解决...根据 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 ;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-08
      • 1970-01-01
      • 2018-01-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多