android - 如何拉伸(stretch)布局以填满屏幕?

标签 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 拉伸(stretch)但 LinearLayout 没有..

enter image description here

最佳答案

尝试添加

android:fillViewport="true"

在你的 ScrollView 中。

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

关于android - 如何拉伸(stretch)布局以填满屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6133004/

相关文章:

android - 在带有 Ellipsize end 的单行中设置 AutocompleteTextView 提示

android - ConstraintLayout 内的 Wrap_content View 延伸到屏幕外

android - Android XML 样式属性是否未按顺序覆盖?

android - 检查 View 在屏幕上是否可见

android - 在 Android 虚拟设备上使用条码扫描仪

android - 如何创建一个包含 RealmList 的新 RealmObject

android - 将 ActionBar 主页按钮设置为右侧

android - https 简单获取请求

android - 如何以编程方式接听电话

android - Spinner OnItemSelected 不适用于自定义行布局