dud*_*eck 5 android android-collapsingtoolbarlayout android-nestedscrollview
我NestedScrollView在布局上遇到了问题CollapsingToolbarLayout。当我将文本滚动到底部时,导航栏覆盖了最后一句。
<?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:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="250dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleTextAppearance="@style/ExpandedAppBar"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:title="Title">
<ImageView
android:id="@+id/toolbar_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/visit_at_office"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/lorem_ipsum" />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
向 TextView 添加边距底部修复了这个错误,但我想知道任何更好的解决方案以及为什么会发生这种情况。请问有人可以帮我吗?
小智 5
如果有人仍在寻找此问题的解决方案:
问题的原因是 CoordinatorLayout 没有正确计算 CollapsingToolbarLayout 的大小,因为它有 Toolbarapp:layout_collapseMode="pin"设置。它认为 CollapsingToolbarLayout 将折叠到零高度,因此它将所有可用空间留给 NestedScrollView,但实际上发生的情况是工具栏保持固定状态,因此 NestedScrollView 向下移动,位于 NavigationBar 后面。
解决此问题的最简单方法就是将android:minHeight="?attr/actionBarSize"(或您使用的任何工具栏高度)添加到 CollapsingToolbarLayout。这样 CoordinatorLayout 将正确地知道它需要为 NestedScrollView 留下多少空间。