ScrollView底部出现白色空白区域

6

我有一个ScrollView的问题,它在底部留下了一片空白。其中填充了几个TextView和GridView,应该填满整个RelativeLayout的父容器。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context=".showPictures">
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView.../>
            <GridView.../>
        ...
        </LinearLayout>
    </ScrollView>
</RelativeLayout>

有人知道出了什么问题吗?


分享截图 - Fahim
将父视图(RelativeLayout)的高度设置为match_parent。 - Wicked161089
将ScrollView的高度设置为wrap_content - Apurva
4个回答

5

让您的相对布局高度与父级匹配,并在滚动视图中使用android:fillViewPort =“true”

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

//...

2

您可以使用此代码来避免滚动视图底部的额外填充:

android:overScrollMode="never"

1
在我的情况下,我在ScrollView中有一个GridView,导致了这个问题。事实证明,GridLayout中的layout_gravity设置为“center”会导致此问题。
“center_horizontal”对于ScrollView更有意义,但是我在使用“center”的原始布局完成后添加了ScrollView,在某些设备上看到元素超出屏幕时,才出现了问题。
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <GridLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"  // having this as android:layout_gravity="center" causes extra space at bottom!
        android:columnCount="2">

        ....

0

给滚动视图中的每个子项赋予权重,包括线性布局,权重值为1


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