为什么button3在设置layout_gravity =“right”后没有移动?

时间:2012-09-03 08:26:38

标签: android

以下是我的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> 

1 个答案:

答案 0 :(得分:1)

不应该,这就是原因。

右侧layout_gravity仅在您的布局为垂直时才考虑,在这种情况下,它将具有预期的结果。

对于您要做的事情,请在第二个和第三个按钮之间使用间隔符,如下所示:

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

它将填满空间并将按钮向右推。