2012-01-04 16 views
8

4つのボタンを相対レイアウトに配置しました。 私はそれらに同じ幅を持たせて、電話機の任意の画面サイズに対して修正したいと思います。 私のコードは以下の通りです:レイアウトの幅を同じにする

<RelativeLayout 
      android:id="@+id/relativeLayout1" 
      android:layout_width="match_parent" 
      android:layout_height="38dp" > 

      <Button 
       android:id="@+id/button1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentTop="true" 
       android:text="Button" /> 

      <Button 
       android:id="@+id/button2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" 
       android:layout_toRightOf="@+id/button1" 
       android:text="Button" /> 

      <Button 
       android:id="@+id/button3" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" 
       android:layout_toRightOf="@+id/button2" 
       android:text="Button" /> 

      <Button 
       android:id="@+id/button4" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" 
       android:layout_toRightOf="@+id/button3" 
       android:text="Button" /> 

     </RelativeLayout> 

私は変更する必要がありますか?

答えて

15

LinearLayoutに切り替え、すべてのボタンのウェイトを同じにします。例えば

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="38dp" 
    android:orientation="horizontal"> 
    <Button android:layout_weight="1" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" /> 
    <Button android:layout_weight="1" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" /> 
    <Button android:layout_weight="1" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" /> 
</LinearLayout> 
+0

はRelativeLayoutのいずれかの解決策はありますか? – inexcii

+0

私は答えを書いていたとき、別の方法はありませんでした。 –

+4

さて、今はどうですか? – inexcii

関連する問題