gpt4 book ai didi

android - AppBarLayout with RecyclerView 可以在不让 RecyclerView 过度滚动的情况下工作吗?

转载 作者:太空宇宙 更新时间:2023-11-03 10:37:34 25 4
gpt4 key购买 nike

我有一个包含 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>

它在 AppBarLayout 可以随着 RecyclerView 滚动而缩小的地方工作正常,如下面的 GIF 所示。它不会滚动到第 100 行之外。

enter image description here

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

enter image description here

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

enter image description here

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

最佳答案

尝试将 RecyclerView 高度与父级匹配。

关于android - AppBarLayout with RecyclerView 可以在不让 RecyclerView 过度滚动的情况下工作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41060361/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com