android - 嵌套的recyclerview:在组之间滚动时卡住
问题描述
我正在使用嵌套的 RecycleViews 来重现 Google 收件箱的外观。现在,我的问题是,每当我尝试滚动浏览这些项目时,它似乎会在一段时间后“卡住”:
数据已经加载并且相当“静态”(它来自本地数据库,并且加载在主要活动的属性中 - 图像是唯一动态检索的东西,我正在使用 Picasso)。
我已经在嵌套回收器视图之间共享视图池......我也尝试过删除图像,但我仍然没有平滑滚动......
这是我的主要布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:background="#FFE7E8ED">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:titleTextColor="@color/colorWhite" />
<!-- forcing focus due neste layout -->
<!-- https://stackoverflow.com/questions/36923948/recycleview-steals-focus-when-inside-a-nestedscrollview?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa -->
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:paddingTop="?android:attr/actionBarSize">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swiper"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/lista"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbarSize="4dp"
android:scrollbarThumbVertical="@color/lightgray"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.constraint.ConstraintLayout>
</FrameLayout>
<!-- Container for contents of drawer - use NavigationView to make configuration easier -->
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/drawer_viewer" />
</android.support.v4.widget.DrawerLayout>
这是recyclerview项目的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/catalog_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_marginRight="8dp"
android:layout_marginTop="10dp"
android:textAlignment="inherit"
android:textAppearance="@android:style/TextAppearance.Material.WindowTitle"
android:textColor="@android:color/darker_gray"
android:textSize="16sp"
android:textStyle="bold" />
<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:cardElevation="4dp">
<android.support.v7.widget.RecyclerView
android:id="@+id/lista_noticias"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:clipToPadding="false"></android.support.v7.widget.RecyclerView>
</android.support.v7.widget.CardView>
</LinearLayout>
最后,内部recyclerview的item的布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="140dp"
android:maxHeight="140dp"
android:minHeight="140dp"
card_view:cardCornerRadius="0dp"
card_view:contentPadding="2dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/logo"
android:layout_width="73dp"
android:layout_height="73dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:adjustViewBounds="false"
android:scaleType="fitXY"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintTop_toTopOf="parent"
card_view:srcCompat="@mipmap/ic_launcher" />
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ellipsize="end"
android:gravity="center_vertical"
android:lines="1"
android:textAppearance="@android:style/TextAppearance.Material.Title"
android:textSize="16sp"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintStart_toEndOf="@+id/logo"
card_view:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/description"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_below="@id/title"
android:layout_marginBottom="32dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ellipsize="end"
android:gravity="top|center_vertical"
android:lines="3"
android:text="Name"
android:textAppearance="@android:style/TextAppearance.Material.SearchResult.Subtitle"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintStart_toEndOf="@+id/logo"
card_view:layout_constraintTop_toBottomOf="@+id/title"
card_view:layout_constraintVertical_chainStyle="spread_inside" />
<TextView
android:id="@+id/publishDate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:text="10/10/2018 13:50"
android:textAppearance="@android:style/TextAppearance.Material.Small"
android:textSize="10sp"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
有人可以告诉我我错过了什么吗?
谢谢。
解决方案
推荐阅读
- php - 代表论坛网站的泛化案例的最佳方法是什么
- php - 如何获取 HTML 表格值并分配给选择和输入文本字段?
- outlook-addin - Outlook Web App 在对话框 Api 消息中添加父级不起作用
- jquery - 将数据表中的“显示 10 个条目”对齐到右侧而不是左侧
- flowtype - 选项 module_mapper 未解决兄弟项目
- pdf - 如何在 Xamarin Forms 中生成 PDF 第一页的缩略图
- excel - 如何使用 VBA 根据主题和发件人姓名保存 Outlook 电子邮件?
- docker - 在 Docker 容器中运行的 Cosmos Emulator 不导出证书
- javascript - 为什么一个计数器有效而另一个无效?(关闭?)
- ssas - 用于连接两个不同维度成员的 MDX 查询