1

以下は私のActivity.xmlファイルです。ボタンlayout_gravity="right"を設定しましたが、機能しません。理由を教えてもらえますか?ありがとうございます。

<LinearLayout xmlns:android=" http://schemas.android.com/apk/res/android" 
 xmlns:tools=" http://schemas.android.com/tools" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" > 



<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<ImageView 
android:id="@+id/imageView1" 
android:layout_width="303dp" 
android:layout_height="wrap_content" 
android:layout_weight="0.99" 
android:src="@drawable/ic_launcher" /> 

<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_gravity="right" 
android:layout_weight="0.99" 
android:baselineAligned="_baseline" 
android:orientation="horizontal" > 

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

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

<Button 
android:id="@+id/button3" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="right" 
android:text="Button" /> 

</LinearLayout> 

</LinearLayout> 

</LinearLayout> 
4

1 に答える 1

1

それは想定されていない、それが理由です。

right layout_gravityは、レイアウトが垂直である場合にのみ考慮されます。その場合、期待どおりの結果が得られます。

あなたがしようとしていることのために、このように、2番目と3番目のボタンの間にスペーサーを使用してください:

<View android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="1" />

スペースがいっぱいになり、ボタンを右に押します。

于 2012-09-03T08:30:52.813 に答える