无法将一个图像按钮对齐,而另一个图像按钮则向左对齐

时间:2011-04-19 19:02:31

标签: android android-layout

这是我试图在右侧和左侧保留一个图像按钮的xml? 我不知道为什么它没有发生,虽然我也设置了grvity?     

<LinearLayout android:id="@+id/linearLayout1"
      android:layout_height="wrap_content" android:gravity="center_horizontal"
       android:layout_width="wrap_content" android:layout_gravity="fill">
           <ImageButton android:layout_width="wrap_content"
        android:layout_gravity="left" android:id="@+id/imageButton1"
        android:src="@drawable/arrow_button_left"    android:layout_height="wrap_content"></ImageButton>
            <ImageButton android:layout_width="wrap_content"
            android:layout_gravity="right" android:id="@+id/imageButton2"
            android:src="@drawable/arrow_button_right"      android:layout_height="wrap_content"></ImageButton>
    </LinearLayout>

3 个答案:

答案 0 :(得分:18)

您应该使用RelativeLayout代替LinearLayout,并将第二个layout_alignParentRight的{​​{1}}属性设置为ImageButton

true

所以你的布局看起来像:

android:layout_alignParentRight="true"

答案 1 :(得分:1)

您将LinearLayout的宽度设置为wrap_content,因此它具有最小的宽度以将按钮放在其自身内部。这些按钮无法对齐,因为它们没有对齐空间。尝试设置fill_parent

答案 2 :(得分:0)

如果你使用了wrap_content的宽度,可能会忘记android:orientation =“horizo​​ntal”在LinearLayout中。

如上所述,Else Relativle布局非常适合您。