3

Inside a ScrollView I have a LinearLayout. The LinearLayout can be as tall as it wants, but I want its minimum height to be at least as tall as its parent (the ScrollView).

<ScrollView
    ...>
    <LinearLayout
        ...
        android:layout_marginTop="@dimen/some_margin"
        android:minHeight="match_parent">

This does not work. It won't accept "match_parent" for minHeight. So how do I approach this?

Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247

2 Answers2

8

You could use the ScrollView's android:fillViewport="true" property in the xml file like this:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

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

        <!--Rest of the children-->
    </LinearLayout>

</ScrollView>
Mike
  • 4,550
  • 4
  • 33
  • 47
0

So you just want to avoid having wasted real estate when the stuff in the LinearLayout doesn't fill up the space allowed by the ScrollView? How about just setting LinearLayout height to:

android:layout_height="match_parent"

You could set the same on the ScrollView so that it fits its own parent as well, but not strictly necessary.

Riaz
  • 874
  • 6
  • 15