开发者

Defining a ScrollView without setting it's height

开发者 https://www.devze.com 2023-01-13 10:59 出处:网络
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.

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 开发者_JS百科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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消