Android 左右布局重力

Android 左右布局重力,android,layout,Android,Layout,我有一个线性布局,里面有两个线性布局。两个线性布局都有2个按钮。我想将前两个按钮向左对齐,其余两个按钮向右对齐。不幸的是,我有四个按钮(或两个布局)并排 这是我的代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"

我有一个线性布局,里面有两个线性布局。两个线性布局都有2个按钮。我想将前两个按钮向左对齐,其余两个按钮向右对齐。不幸的是,我有四个按钮(或两个布局)并排

这是我的代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:background="@drawable/vat_header_selector"
        android:orientation="horizontal" >

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/btn_numbers"
                android:layout_width="90dp"
                android:layout_height="30dp"
                android:textColor="@drawable/vat_btn_header_textcolor_selector"
                android:background="@drawable/vat_btn_header_selector"
                android:text="Numbers">
            </Button>
            <Button
                android:id="@+id/btn_text"
                android:layout_width="90dp"
                android:layout_height="30dp"
                android:textColor="@drawable/vat_btn_header_textcolor_selector"
                android:background="@drawable/vat_btn_header_selector2"
                android:text="Words">
            </Button>   
        </LinearLayout>

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/btn_black"
                android:layout_width="50dp"
                android:layout_height="30dp"
                android:textColor="@drawable/vat_btn_header_textcolor_selector"
                android:background="@drawable/vat_btn_header_selector"
                android:text="B">
            </Button>
            <Button
                android:id="@+id/btn_white"
                android:layout_width="50dp"
                android:layout_height="30dp"
                android:textColor="@drawable/vat_btn_header_textcolor_selector"
                android:background="@drawable/vat_btn_header_selector2"
                android:text="W">
            </Button>   
        </LinearLayout>

    </LinearLayout>

这就是它的样子:

这就是我想要的:
将以下属性应用于包含
按钮B
按钮W
的第二个线性布局

android:gravity="right"
android:layout_weight="1"

线性布局的方向设置为水平时(视图沿X轴放置),重力
左侧
右侧
不起作用。一种方法是在两个
线性布局之间插入一个空的
视图
,以在它们之间创建一个空间:

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

谢谢$这也行,但我认为Luksprog的解决方案更好。