【问题标题】:Can AppBarLayout with RecyclerView works without letting RecyclerView over-scroll?带有 RecyclerView 的 AppBarLayout 可以在不让 RecyclerView 过度滚动的情况下工作吗?
【发布时间】:2016-12-09 12:19:15
【问题描述】:

我有一个带有 CoordinatorLayout、AppBarLayout 和 RecyclerView 的布局,如下所示。

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#aaa"
    tools:context="com.elyeproj.recycleranimation.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="256dp"
        android:fitsSystemWindows="true"
        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"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android:src="@drawable/cheese_2"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin" />

        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/myRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#aaa"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>

当 RecyclerView 滚动时 AppBarLayout 可能会缩小时,它可以正常工作,如下面的 GIF 所示。它不会滚动到第 100 行之外。

当列表很短时,它是不可滚动的,因为RecyclerView是wrap-content,如下图

但是,当列表不是太短,但不长于页面高度时,滚动超出了“100”行,并显示了一些空白,如下所示。

我的问题是,对于场景 3,是否有可能防止过度滚动,即滚动只发生到第 100 行,并且 AppBarLayout 仍然部分可见?

【问题讨论】:

    标签: android android-recyclerview android-coordinatorlayout android-appbarlayout


    【解决方案1】:

    尝试 RecyclerView 高度匹配父项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-14
      • 1970-01-01
      • 2015-11-30
      • 1970-01-01
      • 2017-05-31
      • 2021-01-08
      相关资源
      最近更新 更多