0

layout_weigth 0.2 と 0.8 で 2 列のレイアウトを作成しようとしています。それぞれに垂直スクロールが含まれていますが、右側の列では、上部に固定レイアウトを作成し、ボタンを配置し、その下に垂直スクロールを作成したいと考えています。レイアウトの右側にボタンを配置したいので、相対レイアウトを使用します。問題は、relativeLayout 内の任意のボタンまたはテキストビューで android:layout_alignParentRight="true" パラメータを設定すると、幅が必要以上に大きくなることです (重みパラメータが無視されるように見えます)。しかし、固定幅 (300dp) を RelativeLayout に設定すると、列の幅は重みパラメーターで指定されたとおりになります。

では、ボタンをレイアウトの右側に配置して列の幅を節約する正しい方法は何ですか?

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:weightSum="1" >

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_marginLeft="30dp"
        android:layout_weight=".2"
        android:background="@android:color/white"
        android:scrollbars="none" >

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

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="sometext" />
        </LinearLayout>
    </ScrollView>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_weight=".8"
        android:orientation="vertical" >

        <RelativeLayout
            android:id="@+id/MyRelativeLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:background="@android:color/white" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@+id/ToggleButton2"
                android:layout_alignBottom="@+id/ToggleButton2"
                android:layout_alignParentLeft="true"
                android:text="По рейтингу" />

            <ToggleButton
                android:id="@+id/ToggleButton1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toLeftOf="@+id/ToggleButton2" />

            <ToggleButton
                android:id="@+id/ToggleButton2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true" />

        </RelativeLayout>

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white"
            android:scrollbars="none" >

            <view
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                class="my.app.MyAppView"/>
        </ScrollView>

    </LinearLayout>
</LinearLayout>
4

1 に答える 1

0

internalScrollViewLinearLayout layout_widthを に設定すると0dp、重みが実際に有効になります。現在、「wrap_content」の幅が重量パラメーターと競合しています。

于 2013-06-04T16:16:19.393 に答える