【问题标题】:Bottom part of NestedScrollView hidden by navigation bar [Android]导航栏隐藏的 NestedScrollView 的底部 [Android]
【发布时间】:2017-03-02 16:32:03
【问题描述】:

我在 CollapsingToolbarLayout 的布局上遇到了 NestedScrollView 的问题。当我将文本滚动到底部时,导航栏会覆盖最后一句。


layout.xml:

 <?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>

向 TextView 添加边距底部可修复此错误,但我想知道任何更好的解决方案以及为什么会发生这种情况。有人可以帮帮我吗?

【问题讨论】:

    标签: android android-collapsingtoolbarlayout android-nestedscrollview


    【解决方案1】:

    如果有人仍在寻找此问题的解决方案:

    问题的原因是 CoordinatorLayout 没有正确计算 CollapsingToolbarLayout 的大小,因为它的 Toolbar 具有 app:layout_collapseMode="pin" 设置。它认为 CollapsingToolbarLayout 将折叠到零高度,因此它将所有可用空间留给 NestedScrollView,但实际上发生的是工具栏保持固定状态,因此 NestedScrollView 向下移动,位于 NavigationBar 后面。

    解决此问题的最简单方法是将android:minHeight="?attr/actionBarSize"(或您正在使用的任何工具栏高度)添加到 CollapsingToolbarLayout。这样 CoordinatorLayout 将正确地知道它需要为 NestedScrollView 留下多少空间。

    【讨论】:

    • @dudeck 我认为这是正确的答案,如果我们考虑类型 collapmodes,这个解释很有意义
    • 刚收到问题,想对您的回答表示感谢!节省了我很多时间!
    【解决方案2】:

    您已在根布局中添加android:fitsSystemWindows="true",在您的情况下为CoordinatorLayout

    此行将使视图适合全屏。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-13
      • 1970-01-01
      • 1970-01-01
      • 2019-02-21
      • 1970-01-01
      相关资源
      最近更新 更多