Android 标签的重新定位

Android 标签的重新定位,android,ios,positioning,appcelerator,appcelerator-titanium,Android,Ios,Positioning,Appcelerator,Appcelerator Titanium,我想问您,如何使用视图的“中心”属性(例如标签)。如果我设置了它,什么也不会发生,无论我在创建中设置为点x和点y:20,相应的标签都会将自身设置为屏幕的中心,但我需要稍后将其居中 我的代码 var width = Ti.Platform.displayCaps.platformWidth; var height = Ti.Platform.displayCaps.platformHeight; //create simple window var window = Ti.UI.createWi

我想问您,如何使用视图的“中心”属性(例如标签)。如果我设置了它,什么也不会发生,无论我在创建中设置为点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
,因此居中看起来没有变化,因为标签与文本大小相同,您可能要做的是设置
宽度:Ti.UI.FILL
或其他比文本大的宽度,然后您的标签将居中,因为标签的宽度将大于文本。

您能用代码编辑您的帖子吗?thanksvar width=Ti.Platform.displayCaps.platformWidth;变量高度=Ti.Platform.displayCaps.platformHeight//创建简单窗口var window=Ti.UI.createWindow({width:width,height:height,backgroundColor:#ffffff“})//使用预定义的左填充var button=Ti.UI.createButton({title:“Press me”,left:20,color:#000000})向窗口添加按钮;窗口。添加(按钮);button.addEventListener(“单击”,函数(){//这应该将按钮位置设置为中心,但不执行任何操作button.setCenter(宽度/2,高度/2);});window.open();这只是一个基于Mike答案的提示:有时,在相关元素上设置边框或背景色可以提供信息,以便您可以轻松看到它有多大。