【问题标题】:ScrollView white space at bottomScrollView 底部的空白区域
【发布时间】:2015-03-07 17:10:39
【问题描述】:

我遇到了 ScrollView 的问题,它在底部留下了一个空白区域。它填充了几个 TextViews 和 GridViews,应该填充整个 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>

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

【问题讨论】:

  • 分享截图
  • 使父视图(RelativeLayout)高度匹配父视图
  • 设置滚动视图高度为wrap_content

标签: android gridview scrollview


【解决方案1】:

使您的相对布局高度匹配父级,同时在滚动视图中使用 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"
    

    【讨论】:

      【解决方案3】:

      在我的情况下,我在 ScrollView 中有一个导致此问题的 GridView。事实证明,GridLayout 中的 layout_gravity 作为“中心”导致了这个问题。

      'center_horizo​​ntal' 对 ScrollView 来说更有意义,但是我在原始布局完成后添加了 ScrollView(使用 'center'),当我看到元素在某些设备上离开屏幕时,因此出现了问题.

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

      【讨论】:

        【解决方案4】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2020-11-17
          • 2017-06-09
          • 2018-07-11
          • 2012-08-25
          • 2016-02-08
          • 2021-02-15
          • 2020-12-05
          相关资源
          最近更新 更多