Android 线性布局:设计两个视图:一个在左屏幕,一个在右屏幕

Android 线性布局:设计两个视图:一个在左屏幕,一个在右屏幕,android,layout,Android,Layout,我有一个线性布局,其中有一个微调器和一个图像按钮。我希望微调器在左屏幕上,图像按钮在右屏幕上(两者都在同一屏幕上)。以下是我的布局: <LinearLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal"> <Spinner

我有一个线性布局,其中有一个微调器和一个图像按钮。我希望微调器在左屏幕上,图像按钮在右屏幕上(两者都在同一屏幕上)。以下是我的布局:

<LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:orientation="horizontal">

        <Spinner
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:layout_alignParentTop="true"
            android:id="@+id/spinner_method_list"></Spinner>

        <ImageButton
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/ic_menu_refresh"/>

    </LinearLayout>

在上面的代码中,我认为将布局权重设为1的make
ImageButton
可以工作,但实际上不行。请告诉我如何设计这个布局


谢谢:)

首先,
android:layout\u alignParentTop=“true”
不仅仅是
LinearLayout
的属性。第二,在
水平
线性布局中使用
布局重量
时,
布局宽度
应为0dp,而
垂直
线性布局中的
布局高度
应为0dp

使用<代码>线性布局< /代码>,实现这一点的一种方法是给每个<代码>视图<代码>这里有一个<代码> LayOutoSuths,例如1,然后创建一个第二个<代码>视图>代码>中间,它有一个<代码>重量<代码> 2,但是你需要玩这些来得到你想要的东西。

<LinearLayout
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:orientation="horizontal">

    <Spinner
        android:layout_height="wrap_content"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:id="@+id/spinner_method_list"/>

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

    <ImageButton
        android:layout_height="wrap_content"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:background="@drawable/ic_menu_refresh"/>

</LinearLayout>
如果你想让它们占据屏幕的一半,你可以给它们一个
layout\u weight
的“1”和
layout\u width
的“0dp”

<RelativeLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent">

    <Spinner
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_alignParentLeft="true"   <!-- here  -->
        android:id="@+id/spinner_method_list"/>

    <ImageButton
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:background="@drawable/ic_menu_refresh"
        android:layout_alignParentRight="true"/>    <!-- and here  -->

</RelativeLayout>