2009-08-12 5 views
3

android layout.xmlファイルに2行のボタンを作成しようとしています。 最初の行は左揃えで、2番目の行は中央揃えです。android layout.xmlファイルに2行のボタンを作成するには

これは私がやったことですが、私は1行のボタンを得ることになります。私は何が間違っているのか教えていただけますか?

enter code here 
<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="fill_parent"> 
<LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_gravity="bottom|left" 
     > 
     <Button 
      android:id="@+id/btn1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      /> 
     </LinearLayout> 
    <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_gravity="bottom|center" 
     > 
     <Button 
      android:id="@+id/btn2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      /> 
     <Button 
      android:id="@+id/btn3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      /> 
     </LinearLayout> 
</FrameLayout> 
</pre> 

答えて

5

このタスクではFrameLayoutが間違っています。ここに行くためでframeLayoutが何であるかの説明のための

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:orientation="vertical" 
android:layout_height="fill_parent"> 
<LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_gravity="bottom|left" 
     > 
     <Button 
      android:id="@+id/btn1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      /> 
     </LinearLayout> 
    <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_gravity="bottom|center" 
     > 
     <Button 
      android:id="@+id/btn2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      /> 
     <Button 
      android:id="@+id/btn3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      /> 
     </LinearLayout> 
</LinearLayout> 

:このような 使用のLinearLayout http://developer.android.com/reference/android/widget/FrameLayout.html

0

また、単に1 RelativeLayoutの代わりに、あなたのレイアウトのすべてを使用することができます。私は、RelativeLayoutがLinearLayoutより少ないリソースを使用するという多くのレポートを読んできました。

+0

相対レイアウトは、はるかに高価なレイアウトメカニズムです。ソース、Googleエンジニア:https://plus.google.com/+KirillGrouchnikov/posts/fFfm7jKn7q5 –

+0

リンクされた「記事」(文章に近い)は、アダプタ内のレイアウトについて話しています。 OPではこれをアダプターに入れる必要はありません。言葉が聖なる神の口から出てくるからといって、それ以上のことは起こっていないわけではありません。 –

2

あなたは、行の形式で、ボタンを表示するためのTablelayoutを使用することができます。

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/root" 
     android:stretchColumns="*" 
     android:background="#000000"> 
    <TableRow android:layout_margin="0dip" 
     android:id="@+id/first_row"> 
    <Button android:id="@+id/button01" 
      android:layout_width="0dip" 
      android:layout_weight="1" 
      android:padding="15dip" /> 
    <Button android:id="@+id/button02" 
      android:layout_width="0dip" 
      android:layout_weight="1" 
      android:padding="15dip" /> 
    <Button android:id="@+id/button03" 
      android:layout_width="0dip" 
      android:layout_weight="1" 
      android:padding="15dip" /> 
    <Button android:id="@+id/button04" 
      android:layout_width="0dip" 
      android:layout_weight="1" 
      android:padding="15dip" /> 
    <Button android:id="@+id/button05" 
      android:layout_width="0dip" 
      android:layout_weight="1" 
      android:padding="15dip" /> 
    </TableRow> 
</TableLayout> 
関連する問題