2011-09-08 76 views
4

以下是我的代码。它完美适用于iPhone,但图像对于Android来说非常有用,所以它没有显示标签。如何在Titanium中的按钮上放置图像和标签?

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); 

请帮我这个。我是新来的钛

回答

1

尝试设置的所有对象(butttons /标签)性能在Android中,如:

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

希望这有助于。

+0

这不是在我身边工作,仍然是同样的问题 – spaleja

0

尝试创建第一个视图,然后添加到视图按钮,然后添加到视图图像视图,通过这你会实现你想要的。

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); 
相关问题