【问题标题】:CollapsingToolbarLayout makes RecyclerView NOT scrollable until bottom after fragment view recreationCollapsingToolbarLayout 使 RecyclerView 在片段视图重新创建后无法滚动直到底部
【发布时间】:2020-08-05 13:37:01
【问题描述】:

在第一个片段中,我有一个带有固定工具栏的CollapsingToolbarLayout。对于 CollapsingToolbarLayout,我已将 layout_scrollFlags 设置为 "scroll|exitUntilCollapsed",因为我希望 Toolbar 保持固定。

当我向下滚动以使 CollapsingToolbarLayout 折叠时,然后单击 RecyclerView 中的任何项目以导航到下一个屏幕,然后在单击后退按钮后返回第一个屏幕 我看不到也无法滚动到最后一个项目。如果我首先滚动到顶部并使 CollapsingToolbarLayout 展开,我可以滚动到最底部。看起来 CollapsingToolbarLayout 从 RecyclerView 底部吃掉了一个等于 Toolbar 高度的垂直空间。

但是,如果我从 layout_scrollFlags 中删除 exitUntilCollapsed 并使用其他人,问题就消失了,但工具栏会折叠。

我已经尝试过材质库版本 1.1.0 和 1.2.0 以及最新的 1.3.0-alpha02。所有这些版本似乎都存在此问题。

我想知道是我的代码有问题还是库中的错误?

<com.google.android.material.appbar.CollapsingToolbarLayout
    android:id="@+id/collapsing_toolbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_scrollFlags="scroll|exitUntilCollapsed"
    app:statusBarScrim="@color/colorTransparent"
    app:titleEnabled="false"
    app:toolbarId="@+id/toolbar">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/first_fragment_tv_first_row"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginTop="?attr/actionBarSize"
            android:layout_marginEnd="16dp"
            android:gravity="start"
            android:text="First row"
            android:textColor="@color/colorWhite"
            android:textSize="30sp"
            android:textStyle="bold"
            app:layout_constrainedWidth="true"
            app:layout_constraintBottom_toTopOf="@+id/first_fragment_tv_second_row"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_goneMarginBottom="16dp" />

        <TextView
            android:id="@+id/first_fragment_tv_second_row"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp"
            android:layout_marginBottom="8dp"
            android:fontFeatureSettings="smcp,c2sc"
            android:gravity="start"
            android:text="Second row"
            android:textColor="@color/colorWhite"
            android:textSize="16sp"
            app:layout_constrainedWidth="true"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/first_fragment_tv_first_row" />

    </androidx.constraintlayout.widget.ConstraintLayout>

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        app:layout_collapseMode="pin"
        app:popupTheme="@style/AppTheme.PopupOverlay">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="First Fragment"
            android:textColor="@color/colorWhite"
            android:textSize="16sp"
            android:textStyle="bold" />

    </androidx.appcompat.widget.Toolbar>

</com.google.android.material.appbar.CollapsingToolbarLayout>

【问题讨论】:

    标签: android android-recyclerview android-collapsingtoolbarlayout material-components


    【解决方案1】:

    我在material-components-android Github 页面上创建了一个issue

    现在问题已关闭,据说已在this commit 中修复。当我详细了解哪个版本的库包含该修复程序时,我会更新我的答案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-05
      • 1970-01-01
      • 2016-06-16
      • 1970-01-01
      相关资源
      最近更新 更多