2011-07-09 3 views
0

スケッチレイアウトを見てください。このようなレイアウトを取得するために使用するコンテナは何ですか?

私は5つのボタン、画面の中央に位置し、このように配置されている必要があります。どのような種類のコンテナ要素を使用する必要がありますか - TableLayoutまたはRelativeLayoutまたは3番目のレイアウト?

+0

のようなものを使用することになり、宿題フラグを使用することを覚えている:私はちょうどこれまでの(それがどのように動作するか確認するためにandroid:gravityプロパティを参照してください)ホイップ。 –

+0

もっと複雑なレイアウトのほんの一部です:)) – sandalone

答えて

2

これは宿題であれば、私はこの

<LinearLayout android:orientation="vertical" ....> 
    <RelativeLayout ... > 
     // place the buttons in the desired padding 
    </RelativeLayout> 
    <RelativeLayout ... > 
     <Button ... android:layout_centerHorizontal="true" ... /> 
    </RelativeLayout> 
    <RelativeLayout ... > 
     // place the buttons in the desired padding 
    </RelativeLayout> 
</LinearLayout> 
+0

これは良い見えます。明日はまずそれを試してみる。 – sandalone

0

私は相対possitionとelemnts(それはコンテナ内であるかどうか、絶対的に依存して)示唆

2

あなたは相対的なレイアウト、

ステップ1を使用することができます:あなたの最初のボタンを作成後、第2のボタンを作成します最初のボタン

ステップ2にleftof第二ボタンを作る:最初のボタンの下に第3ボタンを作成

ステップ3:第3ボタンの下に第四及び第五のボタンを作成

0

あなたはいつもあなたが見せてくれるような行にしたいのですが、それらを列に入れたくないと思うので、私はTableLayoutに行きません。 RelativeLayoutは良いです。

または、レイアウトを組み合わせるのはどうですか?この状況で

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" android:gravity="center_vertical"> 
    <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal"> 
     <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
     <Button android:text="Button" android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
    </LinearLayout> 
    <LinearLayout android:id="@+id/linearLayout2" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal"> 
     <Button android:text="Button" android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
    </LinearLayout> 
    <LinearLayout android:id="@+id/linearLayout3" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal"> 
     <Button android:text="Button" android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
     <Button android:text="Button" android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
    </LinearLayout> 

</LinearLayout> 
+0

ボタン間のスペースはどうですか?この方法で、彼らはお互いに触れるだろう、そう? – sandalone

+1

どのくらいのスペースが必要でしたか?あなたはあなたの質問にそのことを言っていませんでした。 :P Eclipseでそのレイアウトをそのまま見ると、外観に触れることはありませんが、触れることができる矩形があります。それらの間にスペースを増やしたい場合は、必要なものに応じて、各ボタンまたは各サブレイアウトのマージンを指定します。 ppではなくdp単位を使用することを忘れないでください。 :) – Ribose

関連する問題