泡泡聊天钛

时间:2014-06-03 21:26:27

标签: javascript titanium titanium-alloy

https://developer.appcelerator.com/question/146449/how-do-i-make-a-view-with-a-bubble-but-with-a-continuous-border

我找到了这个教程,我正在尝试用钛创建一个泡泡聊天窗口。

然而,我遇到的麻烦是我无法获得标签的高度/宽度,直到我将其粘贴到窗口和视图内部,即使这样,如果标签太小,泡泡聊天也会变形。< / p>

在钛合金中实现这一目标的最佳方式是什么,谢谢。

var label1 = Titanium.UI.createLabel({
    color : '#999',
    text : 'I am Window 1',
    font : {
        fontSize : 20,
        fontFamily : 'Helvetica Neue'
    },
    textAlign : 'center',
    height : 'auto',
    width : 'auto',
});


var bubble1 = Ti.UI.createView({
    backgroundImage : 'bubble.png',
    backgroundLeftCap : 43,
    backgroundRightCap : 34,
    backgroundTopCap : 34,
    backgroundBottomCap : 36,
    height : 10,
    top : 10,
    visible: false,
    width : 10
});

bubble1.add(label1);
win1.add(bubble1);

1 个答案:

答案 0 :(得分:0)

要获得标签使用的高度/宽度:label1.toImage().widthlabel1.toImage().height

并且最好的方法是: 将标签添加到View后,您需要:

  1. 检查标签的宽度,如果它太长,并且超过屏幕宽度,则将标签宽度更改为屏幕尺寸 - 50像素。 if(label1.toImage().width > Ti.Platform.displayCaps.getPlatformWidth()) label1.width = Ti.Platform.displayCaps.getPlatformWidth() -50;
  2. 将View的宽度更改为相同的标签宽度。
  3. 设置label1.heigh = Ti.UI.SIZE(现在不支持自动)
  4. 设置View.height = Ti.UI.SIZE
  5. 要检查小尺寸,您可以这样做:

    if(Ti.Platform.displayCaps.getPlatformWidth() < 100){ label1.width = 100; View.width = Ti.UI.SIZE; }