简体   繁体   English

钛“ label.width”适用于iOS,但不适用于Android

[英]Titanium “label.width” works for iOS but not for Android

I am developing an app in titanium, and completed the iOS version successfully. 我正在开发钛合金应用程序,并成功完成了iOS版本。 Android is presenting some problems, here is one. Android存在一些问题,这是一个问题。

The view contains a number of labels to display data in the format A: B (note that B is bold). 该视图包含许多标签,以A: B格式显示数据(请注意,B为粗体)。 That bold part is necessary, and the reason I need two labels. 该粗体部分是必要的,原因是我需要两个标签。

This is the code I am using: 这是我正在使用的代码:

if(restaurant && !(restaurant=='no' && restaurant.length=='2')){
    var restaurant_label = Ti.UI.createLabel({
        text:'Restaurant:',
        left:3,
        height:20,
        width:'auto',
        top:0,
        textAlign:'left',
        color:'#000',
        font:{
            fontFamily:'Helvetica Neue',
            fontSize:13,
            fontWeight:'Regular'
        }
    });
    view.add(restaurant_label);
    var restaurant_value = Ti.UI.createLabel({
        text:restaurant,
        left:restaurant_label.width+10,
        height:'auto',
        width:'auto',
        top:-18,
        textAlign:'left',
        color:'#000',
        font:{
            fontFamily:'Helvetica Neue',
            fontSize:13,
            fontWeight:'Bold',
            fontStyle:'Italic'
        }
    });
    view.add(restaurant_value);
    check_localservices = false;
}

The "value" label needs to be in the right spot, but android does not seem to be able to get the width of the previously added label. “值”标签必须位于正确的位置,但是android似乎无法获取先前添加的标签的宽度。

What gives? 是什么赋予了?

It appears in a bug report that there was some question as to what it suppose to be reported by a label.width query. 在错误报告中,似乎有人对label.width查询应该报告的内容有疑问。 According to the bug report for version 1.7, a correct response to YOUR query should return 'auto' on Android. 根据1.7版的错误报告,对您的查询的正确响应应在Android上返回“自动”。 This is the case because you have 'auto' as the value for width. 之所以如此,是因为您将'auto'作为宽度的值。 Does it return 'auto'? 它返回“自动”吗?

https://jira.appcelerator.org/browse/TIMOB-3202 https://jira.appcelerator.org/browse/TIMOB-3202

It so happens that it looks like the correct code is listed there to get the value you are looking for. 碰巧看起来好像那里列出了正确的代码,以获得您要寻找的值。 I haven't tested this, but it appears you might be querying the wrong value. 我尚未对此进行测试,但看来您可能在查询错误的值。

For your situation it appears you want to use: 根据您的情况,您似乎要使用:

var restaurant_value = Ti.UI.createLabel({
        text:restaurant,
        left:restaurant_label.size.width+10, // <===== size
        height:'auto',
        width:'auto',
        top:-18,
        textAlign:'left',
        color:'#000',
        font:{
            fontFamily:'Helvetica Neue',
            fontSize:13,
            fontWeight:'Bold',
            fontStyle:'Italic'
        }
    });

According to the comments, you might need to also query the size property after 'opening' the window. 根据评论,您可能还需要在“打开”窗口后查询size属性。 If you look at Paul Dowsett's answer, he has an example of a listener on the 'open' event. 如果您看一下Paul Dowsett的回答,他有一个“开放”事件中的监听者的例子。

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

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