重新定位标签



我想问您,如何使用视图的"center"属性(例如标签)。如果我设置了它,什么都不会发生,无论我在创建中设置为点x和y:20,相应的标签都会将自己设置为屏幕的中心,但我需要稍后将其居中。

我的代码

var width = Ti.Platform.displayCaps.platformWidth;
var height = Ti.Platform.displayCaps.platformHeight; //create simple window 
var window = Ti.UI.createWindow({
        width:width,
        height:height,
        backgroundColor:"#ffffff"
}); 
//add button to window with predefined left padding 
var button = Ti.UI.createButton({ 
        title:"Press me", 
        left:20, 
        color:"#000000" 
});
window.add(button);
button.addEventListener("click", function() { 
    //this should set button position to center, but does nothing  
    button.setCenter(width/2, height/2);
});
window.open();

只是猜测,没有代码可看,但可能发生的情况是,您的标签被设置为width:Ti.UI.SIZE,因此居中看起来没有任何变化,因为标签的大小与文本相同,您可能想做的是设置width:Ti.UI.FILL或比文本大的其他宽度,然后您的标签将居中,因为标签宽度将大于文本。

最新更新