【问题标题】:How can I place an image and label on button in Titanium?如何在 Titanium 中的按钮上放置图像和标签?
【发布时间】:2011-09-08 06:03:40
【问题描述】:

下面是我的代码。它在 iPhone 上完美运行,但图像在 Android 上被拉伸,所以它不显示标签。

var friendsButton = Titanium.UI.createButton({
    top : 0,
    left : 91,
    width : 90,
    height : 101,
    style : 0,
    backgroundImage : '/img/buttonMiddle.png',
    image : '/img/friendcopy.png'
});
var friendLabel = Titanium.UI.createLabel({
    top : 35,
    left : 25,
    width : 100,
    height : 100,
    text : 'Friend',
    color : 'white',
    font : {fontSize:12}
});
friendsButton.add(friendLabel);

请帮助我。我是钛新手

【问题讨论】:

    标签: titanium titanium-mobile


    【解决方案1】:

    尝试在 Android 中设置所有对象(按钮/标签)属性,例如:

    var friendLabel = Titanium.UI.createLabel({
        top : '35dp',
        left : '25dp',
        width : '100dp',
        height : '100dp',
        text : 'Friend',
        color : 'white',
        font : {fontSize:'12dp'}
    });
    

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      尝试创建第一个视图,然后添加到视图按钮,然后添加到视图图像视图,这样你就可以实现你想要的。

      var buttonview = Ti.UI.createView();
      buttonview.width = '50pt';
      buttonview.height = '50pt';
      
      var button = Ti.UI.createButton();
      button.width = Ti.UI.FILL;
      button.height = Ti.UI.FILL;
      button.title = 'Activity';
      button.verticalAlign = Ti.UI.TEXT_VERTICAL_ALIGNMENT_BOTTOM;
      button.font = 
      {
         fontSize: '5pt',
         fontWeight : 'bold',
      };
      
      buttonview.add(button);
      
      var imageview = Ti.UI.createImageView();
      imageview.image = '/activities.png';
      imageview.height = '80%';
      imageview.width = '80%';
      imageview.top = '1pt';
      buttonview.add(imageview);
      

      【讨论】:

        猜你喜欢
        • 2012-02-25
        • 2011-03-25
        • 2018-05-29
        • 2017-07-13
        • 1970-01-01
        • 1970-01-01
        • 2018-12-23
        • 1970-01-01
        • 2022-12-17
        相关资源
        最近更新 更多