gpt4 book ai didi

android - 带有 CoordinatorLayout 的嵌套 RecyclerView

转载 作者:IT老高 更新时间:2023-10-28 22:25:25 30 4
gpt4 key购买 nike

我的问题就像这里提出的问题:Scroll behavior in nested RecyclerView with horizontal scroll

类似于 Google Play 商店 UI,我在父 RecyclerView(垂直滚动)中有一个嵌套的 RecyclerView(水平)。父级 RecyclerView 是 CoordinatorLayout 的子级,其中每当父级 RecyclerView 滚动时,工具栏就会展开和折叠。

当我们触摸子 RecyclerView(查看下面的图片 1)并向上滚动时,一切正常,然后 CollapsingToolbar 折叠,但是当我触摸其中一个子 RecyclerView 并向上滚动时,然后CollapsingToolbar 的折叠不会发生。

[下图显示当我们在精选和趋势之间触摸并向上滚动时] enter image description here

[下图显示当我们触摸精选列表并向上滚动] enter image description here

更新:

CoordinatorLayout 的 Activity

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coord_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.ChannelHubOld">

<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
android:fitsSystemWindows="true">
<RelativeLayout
android:background="@color/pkDarkGrey"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="200dp">

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/sidebar_header"/>
</RelativeLayout>

<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:theme="@style/ActionBarWidget"/>

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

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

<!-- Parent RecyclerView --->

<android.support.v7.widget.RecyclerView
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recycler_view_pagelayout"
/>

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

最佳答案

有同样的问题。通过设置 setNestedScrollingEnabled(false) 修复在水平嵌套的 RecyclerViews 上。在未设置此选项时,CoordinatorLayout.Behavior 似乎没有正确拦截嵌套滚动。试试看!


注意:您还必须向内部(嵌套)RecyclerView 添加布局行为(例如:app:layout_behavior="@string/appbar_scrolling_view_behavior")才能正常工作

关于android - 带有 CoordinatorLayout 的嵌套 RecyclerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34791752/

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