Android布局问题 - 线性布局高度未填满滚动视图高度

5

我遇到了一个轻微的Android布局问题...

我有一个包含 LinearLayout 的 ScrollView 元素。我希望滚动视图填满整个设备屏幕,而线性布局填满滚动视图的整个高度。

我现在的代码导致 ScrollView 填满整个屏幕,但是 LinearLayout 只填满了 ScrollView 高度的一半左右。

以下是我的代码:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ff036c07">
    <LinearLayout
        android:background="#FF0000"
                android:id="@+id/overview_form"
                xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:orientation="vertical"
                android:layout_width="fill_parent"
              android:layout_height="fill_parent">


</LinearLayout>
</ScrollView>

有什么想法我错过了吗?

为什么你想让LinearLayout填满整个屏幕? 它会根据滚动条的大小而增长。 如果是因为背景或其他原因,你只能在ScrollView中设置它。 - rachit
android:fillViewport="true" 转为 ScrollView。 - user755
3个回答

16
在ScrollView中添加android:fillViewport="true"属性。

5
在你的ScrollView中添加android:fillViewport="true"属性,并从LinearLayout中删除不必要的命名空间xmlns:android="http://schemas.android.com/apk/res/android"。

0
尝试添加权重属性,在LinearLayout中加入android:weight="1"并检查。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接