android - NestedScrollView 内容小于屏幕高度
问题描述
我知道这个问题经常被问到,但在我的情况下我找不到正确的方法。
正如您在我的 xml 文件中看到的,我正在使用 CoordinatorLayout、NestedScrollView 和 AppBarLayout。当nestedScrollview 的内容小于屏幕高度时,它让空白的额外空间一无所获。
我怎样才能删除这个空白的额外空间?
谢谢大家
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f000f0"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<!-- more content but not enought to fill screen -->
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.AppBarLayout
android:id="@+id/main_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#ff0000">
<TextView
android:id="@+id/main_linearlayout_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="30dp"
android:text="PSEUDO"
android:textColor="#ffffff"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimaryDark">
<!-- some content (title) -->
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CoordinatorLayout>
编辑 1:
- 没有滚动
- 使用 NestedScrollView 高度 wrap_content
- 使用 NestedScrollView 高度 match_parent (所以它是同样的问题,而不是有空白空间,它是粉红色的,但它是一个额外的无用空间)
所以要明确的是,我在最后一个“Hello World”下什么都不想,也不要滚动超过必要的范围。
解决方案
将您的高度设置NestedScrollView
为match_parent
.
推荐阅读
- r - 将两个元素列表合并为一个具有相同元素但每个元素有两个变量的列表
- javascript - 动态更改分配的点击功能
- ios - 崩溃的范围:com.apple.main-thread EXC_BREAKPOINT on ViewController Initialisation
- python - 对 Pandas 中的整个数据框应用数学运算
- sql - 如何根据特定数据的模式对批量表中的数据进行分组?
- c# - 部分类中的自定义属性(列名无效)
- javascript - 如何在 angular.js 中从旧路径重定向用户?
- c - 自定义 Windows 身份验证包的实现 - LsaApUserLogonEx
- gradle - 为什么实施 gradle 依赖项会暴露给消费者
- web-services - 过滤器语法错误