2016-03-31 14 views
0

ビューの "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(); 
+0

あなたのコードで投稿を編集できますか?ありがとう – Giordano

+0

var width = Ti.Platform.displayCaps.platformWidth; var height = Ti.Platform.displayCaps.platformHeight; //単純なウィンドウ VARウィンドウ= Ti.UI.createWindow作成({ 幅:幅、 高さ:高さ、 のbackgroundColorを "#1 FFFFFF" })。 は、事前定義された左パディング VARボタンでウィンドウにボタンを追加// = Ti.UI.createButton({ タイトル:20、 色:、 左の "私を押して" "#000000" を})。 window.add(button); button.addEventListener( "click"、function() { //ボタンの位置を中央に設定する必要がありますが、何もしません。 button.setCenter(width/2、height/2); }); window.open(); –

答えて

0

だけを見て、コードなしで推測が、おそらく何が起こっていることはあなたのラベルは、ラベルが同じサイズであるため、何も変わっていないようなので、センタリングが見えwidth:Ti.UI.SIZEに設定されていますテキストは、おそらく何をしたいのですか?width:Ti.UI.FILLまたは他の幅をテキストより大きく設定すると、ラベルの幅がテキストよりも大きくなるため、ラベルが中央になります。

+0

マイクの答えを基にしたちょっとしたヒント:時には、それがどれほど大きいかを簡単に確認できるように、問題の要素に境界線や背景色を設定することが有益な場合があります。 –