0

画面全体を埋める水平レイアウト内に 3 つのボタンがあります。

<LinearLayout   
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
android:layout_width="100dp"
android:layout_height="50dp" 
android:text="1" />

<Button 
android:layout_width="100dp"
android:layout_height="50dp" 
android:text="2"/>

<Button 
android:layout_width="100dp"
android:layout_height="50dp" 
android:text="3"/>

私の2つの問題は次のとおりです。

  1. 幅を変更せずに右ボタンを画面の右端に固定するにはどうすればよいですか?

  2. 幅を変更せずに、ボタン 1 と 3 の間の空きスペースをボタン 2 で埋めるにはどうすればよいですか?

4

4 に答える 4

2

ビューの重みは、ビューが埋める残りのスペースの割合です。

<LinearLayout   
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <Button
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:text="1" />

    <Button
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:text="2"/>

    <Button 
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:text="3"/>

</LinearLayout>
于 2013-09-18T14:37:02.150 に答える
0

相対レイアウトを使用することが、このような最良の解決策になると思います。

<RelativeLayout   
 android:layout_width="fill_parent" 
      android:layout_height="wrap_content"
     >



  <LinearLayout   
    android:layout_width="wrap_content" 
     android:layout_height="wrap_content"
   android:orientation="horizontal"
android:layout_toLeftOf="@+id/button3"
android:alignParentLeft=”true”&gt;

<Button
android:layout_width="0dp"
android:layout_height="50dp" 
android:text="1" 
android:layout_weight="1"/>

<Button 2
android:layout_width="0dp"
android:layout_height="50dp" 
android:text="2"
android:layout_weight="1"/>
</LinearLayout>

<Button 3
android:id=”@+id/button3”
android:layout_width="100dp"
android:layout_height="50dp" 
android:text="3"
android:alignParentRight=”true”/>

</RelativeLayout>
于 2013-09-18T14:40:11.787 に答える