cooperok
cooperok

Reputation: 4257

RelativeLayout takes more place that parent layout

I'm trying to make layout with 2 columns, with layout_weigth 0.2 and 0.8. Each of them contains vertical scroll, but in right column i want to make fixed layout at the top, with buttons, and below them vertical scroll. I want to place buttons at the right part of the layout, so i use relative layout. The problem is that when i'm set android:layout_alignParentRight="true" param at any button or textview inside relativeLayout it's width becomes bigger than need (looks like weight params are ignored). But when i'm set fixed width (300dp) to RelativeLayout, width of columns are as specified in weight params.

So what is the right way to put buttons to right part of the layout and save width of columns?

<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>

Upvotes: 0

Views: 89

Answers (1)

Yevgeny Simkin
Yevgeny Simkin

Reputation: 28349

Set your internal ScrollView and LinearLayout layout_width to 0dp, then the weights will actually take effect. Right now your "wrap_content" width is conflicting with the weight param.

Upvotes: 0

Related Questions