Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stretch Layout to fill screen?

I have simple layout like this: (it's for mail)

<ScrollView android:layout_height="0dp" android:layout_width="fill_parent" android:layout_weight="1" android:background="@color/red_start">

        <LinearLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical" android:background="@color/blue_start">

            <TextView style="@style/MyTextViewLabel" android:text="From" android:layout_marginTop="5dp"/>

            <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/shape_white_rounded">
                <TextView style="@style/MyTextViewLabel.Black" android:id="@+id/tv_sender" />
            </LinearLayout>

            <TextView style="@style/MyTextViewLabel" android:text="Subject" android:layout_marginTop="5dp"/>

            <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/shape_white_rounded">
                <TextView style="@style/MyTextViewLabel.Black" android:id="@+id/tv_subject" />
            </LinearLayout>

            <TextView style="@style/MyTextViewLabel" android:text="Body" android:layout_marginTop="5dp"/>

            <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/shape_white_rounded">
                <TextView style="@style/MyTextViewLabel.Black" android:id="@+id/tv_body" />
            </LinearLayout>

        </LinearLayout>

    </ScrollView>

For some reason LinearLayout won't fill ScrollView as I expect. Basically, I want to make tv_body to fill screen and if there is more text - it should be scrollable. Right now it looks like this. I added colors to illustrate that ScrollView stretch but LinearLayout doesn't..

enter image description here

like image 759
katit Avatar asked May 26 '11 02:05

katit


1 Answers

Try to add

android:fillViewport="true"

in your ScrollView.

Checkout this for more explanations : http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/

like image 64
Matthieu Avatar answered Oct 04 '22 02:10

Matthieu