1

ビューの水平方向の中央に配置したいボタンがあります。3つあり、私が得ることができるのは次のとおりです。

[button1-button2-button3------------------------------]

私が本当に欲しいのは

[--------button1--------button2--------button3--------]

これらのボタンも動的な幅です。ボタンの数は変わります。1 つのビューもあれば、2 つまたは 3 つのビューもあります。アクションに応じて、ボタンの数が変わる可能性があります。iOSとAndroidの両方をサポートする必要があります。

4

6 に答える 6

2

nパーセンテージ レイアウトを使用して、画面を異なる列に分割してみてください。次に、ボタンをそれぞれの非表示コンテナーに追加します。

var n = // Your number of buttons horizontal
var container = Ti.UI.createView({width : "100%", layout: "horizontal" });
for(var i=0;i<n;i++) {
   var column = Ti.UI.createView({
        width : (100/n)+"%",
   });
   // Create your button here
   // .....
   // .....

   // Now add it to the column
   column.add(yourNthButton);
   // Now add the column to the container
   container.add(column);
}
于 2013-09-12T19:34:02.220 に答える
0

ひえー兄さん

必要な場合は、xml でチタン合金を使用してこれを実現します。その場合、% を使用できます。

Container ------------width 100%-----layout horizontal---------
   first child--------left 10%------- width 20%
    second child--------left 10%------- width 20%
   third child--------left 10%------- width 20%-----right 10%

あなたの答えが得られない場合は、私に知らせてください

スパルタカス ありがとう:)

于 2014-11-06T07:49:37.980 に答える
0

これを試して

var yourView = Ti.UI.createView({ layout:"horizontal"});


    var buttonsHolder = Ti.UI.createView({ width:"100%" }); 

    // this view will hold the buttons
    var button1 = Ti.UI.createButton({title:"button1 , left:0"}); // the left button
    var button2 = Ti.UI.createButton({title:"button2"}); // the middle button
    var button3 = Ti.UI.createButton({title:"button3",right:0}); // the right button

    buttonsHolder(button1);
    buttonsHolder(button2);
    buttonsHolder(button3);

    yourView.add(buttonsHolder);
于 2014-11-04T14:41:43.037 に答える
0

ツールバーを配置できる場合は、「フレックススペース」ボタンを使用できます。これにより、他のボタン間のギャップを埋めるために必要なスペースが作成されます。これは、 titanium docsの単純なツールバーの例の構文です。

var send = Titanium.UI.createButton({
    title: 'Send',
    style: Titanium.UI.iPhone.SystemButtonStyle.DONE,
});

var camera = Titanium.UI.createButton({
    systemButton: Titanium.UI.iPhone.SystemButton.CAMERA,
});

var cancel = Titanium.UI.createButton({
    systemButton: Titanium.UI.iPhone.SystemButton.CANCEL
});

flexSpace = Titanium.UI.createButton({
    systemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE
});

var toolbar = Titanium.UI.iOS.createToolbar({
    items:[send, flexSpace, camera, flexSpace, cancel],
    bottom:0,
    borderTop:true,
    borderBottom:false
}); 
win.add(toolbar)
于 2013-09-12T20:52:55.530 に答える
0

Alloy を使用する場合は、パーセンテージを使用して幅と位置を制御することをお勧めします。次の例では、3 つの小さな画像を大きな画像の下に配置し、これも中央に配置しています。

<TableViewRow selectionStyle="Ti.UI.iPhone.TableViewCellSelectionStyle.NONE" backgroundColor="white" layout="vertical">
    <ImageView id="detailsFeaturedImage" top="10"/>
    <View  height="60">
        <View layout="horizontal">
            <View left="25%" width="10%"><ImageView image="images/thumb-up-7@2x.png" onClick="thumb_up" /></View>
            <View left="10%" width="10%"><ImageView image="images/thumb-down-7@2x.png" onClick="thumb_down"/></View>
            <View left="10%" width="10%"><ImageView image="images/flag-7@2x.png" onClick="flag_for_review"/></View>
        </View>
    </View>
</TableViewRow>
于 2014-12-06T16:30:34.293 に答える