android - 折叠图像时,NestedScrollView 内的 RecyclerView 不会向上滚动
问题描述
这是整个项目的链接,以便您可以重现问题: https ://github.com/FaridArbai/TapExchange/tree/master/TapExchange
我想就一个我已经苦苦挣扎了两天的问题寻求帮助,尽管我已经进行了深入的研究,但仍未找到解决方案。
基本上,我有一个 AppBarLayout,里面有一个 CollapsingToolbarLayout,它的任务是在用户向下滚动 CardViews 的 RecyclerView 时折叠背景图像。当图像完全折叠后我尝试向下滚动 RecyclerView 时出现问题:如果我触摸组成 RecyclerView 的卡片视图之一,它将不会滚动!
这是没有崩溃的外观(在这里我可以毫无问题地滚动):
这是图像折叠后的外观(如果我的手指触摸构成 RecyclerView 的任何卡片视图,我将无法向下滚动):
整个布局的代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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=".profiles.PersonalProfile"
android:background="#FCFCFC">
<android.support.design.widget.AppBarLayout
android:id="@+id/personal_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/personal_collapsing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:contentScrim="?attr/colorPrimary"
app:title=""
app:titleEnabled="false">
<ImageView
android:id="@+id/personal_image_background"
android:layout_width="match_parent"
android:layout_height="340dp"
android:scaleType="centerCrop"
android:src="@drawable/profile_background"/>
<android.support.v7.widget.Toolbar
android:id="@+id/personal_toolbar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title="">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Space
android:id="@+id/avatar_collapsed_target"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="0dp"/>
<TextView
android:id="@+id/personal_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:text="Unknown Username"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/section_selection_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@drawable/ic_action_add" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/personal_image_foreground"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="120dp"
android:layout_gravity="top|center_horizontal"
android:src="@drawable/executive"
app:collapsedTarget="@id/avatar_collapsed_target"
app:layout_behavior="com.faridarbai.tapexchange.graphical.CollapsingAvatarBehavior"
android:elevation="5dp"/>
<LinearLayout
android:id="@+id/personal_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_anchor="@id/personal_image_foreground"
app:layout_anchorGravity="bottom|center"
android:paddingTop="30dp">
<TextView
android:id="@+id/username_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unknown Username"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</LinearLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/personal_nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fillViewport="true">
<android.support.v7.widget.RecyclerView
android:id="@+id/personal_sections_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="0dp" />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
我正在使用 API 25 构建并使用 25.4.0 版的 GUI 实用程序。如果有人能提供帮助,我将不胜感激。
谢谢
编辑
我尝试使用 SDK nº 27 和 27.1.1 构建工具,同时抑制“snap”和 NestedScrollView,但仍然遇到同样的问题:一旦背景图像折叠,如果我最初将手指放在 CardView 上,RecyclerView 将无法向上滚动来自 RecyclerView。这很奇怪,因为 WhatsApp、Facebook 和 Telegram 使用非常相似的布局,而且他们没有这个问题,所以应该有一个很好接受的解决方法。
有人帮忙吗?
解决方案
为什么你在 NestedScrollView 中使用 RecyclerView?!。如果您有更多具有不同布局的项目,您可以使用具有不同 ViewTypes 的 recyclerView,但我不建议在 NestedScrollView 中使用它尝试直接使用它,不要忘记将它放在app:layout_behavior="@string/appbar_scrolling_view_behavior"
recylerView 中,它会起作用。
推荐阅读
- linux - 如何将文件从 docker 映像移动到计算机上的文件夹中
- amazon-web-services - S3 指标的巨大差异 - Cloudwatch vs AWS S3 CLI vs UI“获取大小”
- batch-file - 变量中的 Windows 9x/Me 版本
- swift - 不推荐使用自动配置会话?
- join - SQL TERADATA:我希望根据日期的重复计数创建一个列。没有减少输出行
- .net - linux 上的 Mono:找不到元数据文件“/mscorlib.dll”
- javascript - 查询参数包括#, Javascript (Node) 错误输出
- shell - 通过 sh 脚本运行 xdtool 命令时锁定键盘和鼠标
- azure - 在 Azure AD B2C 中注册后如何让用户返回登录页面?
- bash - Shell 脚本 - 无法将随机值分配给变量