我使用嵌套的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项目的布局:
<?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>
有人可以告诉我我错过了什么吗?
感谢。