如何拉伸布局以填充屏幕?

时间:2011-05-26 02:12:54

标签: android android-layout

我有这样简单的布局:(这是邮件)

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

出于某种原因,LinearLayout不会像我预期的那样填充ScrollView。基本上,我想让tv_body填充屏幕,如果有更多文本 - 它应该是可滚动的。现在它看起来像这样。我添加了颜色来说明ScrollView拉伸但是LinearLayout没有..

enter image description here

2 个答案:

答案 0 :(得分:40)

尝试添加

android:fillViewport="true"
在ScrollView中

查看此内容以获取更多解释:http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/

答案 1 :(得分:0)

如果您将ScrollView中的android:layout_height="0dp"更改为android:layout_height="match_parent"会怎样?

相关问题