views:

111

answers:

1

Hello, I created a ScrollView and want it to expand to the available space, without having to set a fixed height (i.e. "250px") for it.

As such, I created a RelativeLayout. The basic outline follows:

<RelativeLayout>
    <LinearLayout 
        android:id="@+id/x" >
        <TextView 
            android:text="Title" ... />
    </LinearLayout>
    <ScrollView 
        android:id="@+id/y"
        android:layout_below="@id/x" />
    <LinearLayout
        android:layout_below="@id/y" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:gravity="center_horizontal|bottom" >
        <Button ...>
    </LinearLayout>
</RelativeLayout>

The idea of the Layout is to have the Title on top, the Button in near the bottom of the screen and the ScrollView in between those two.

The problem is, I still have to use android_height in the definition of ScrollView, so its still fixed to that height.

How can I work around this?

Thanks.

A: 

Seems like this layout might be simpler with a LinearLayout as the outer element, with orientation="vertical"

Set the layout_height of all elements to wrap_content. Set the weight of all elements other than the scrollView to 0, and the weight of the scrollView to 1.

Mayra
Hello. Thanks. But, setting the layout_height of the ScrollView to fill_parent hides the button in the bottom of the Activity. Other suggestions? Thanks.
MyNameIsZero
Did you try replacing your RelativeLayout with a LinearLayout with orientation="vertical"? All you are doing is stacking up widgets in a vertical line, so the relative layout seems overkill. If you really want the RelativeLayout, you could try messing with the layout_weights.
Mayra
Hello. I tried to replace the RelativeLayout with the LinearLayout (vertically oriented). This still hides the buttons on the bottom of the Activity. Other suggestions? Thanks.
MyNameIsZero
Originally I had a LinearLayout which I replaced with the RelativeLayout in order to attempt to define a ScrollView without a fixed height. Using both Layouts and setting the height of the View to "fill_parent" will hide the buttons in the bottom of the Activity. Any idegas? Thanks.
MyNameIsZero
Gah, sorry, I forgot.. I struggled with something like this for a long time previously. The key is to set the weight of the objects appropriately. See edit. The weight affects how a view will stretch if there is extra space.
Mayra
Thanks for the "weight" tip. By manipulation the "weight" it was possible to achieve the desired layout.
MyNameIsZero