一个CardView中的多个RecyclerView项目

Mos*_*k L 5 android android-viewholder android-cardview android-recyclerview

我正在尝试在每个CardView项目中创建多个RecyclerView项目,因为这个应用程序:

在此输入图像描述

我创建了一个包含数据集项的cardview_item.xml(本例中的匹配项)

以及包含卡片标题的cardview_title.xml(本例中为联盟).

cardview_title.xml:

<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="88dp"
card_view:cardCornerRadius="1dp"
android:layout_margin="4dp">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/amount_title"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_marginEnd="5dp"
        android:layout_marginTop="5dp"
        android:gravity="center"
        android:layout_alignParentEnd="true"
        android:padding="5dp"
        android:text="@string/amount"
        android:textAllCaps="true"
        android:textSize="20sp"
        android:textColor="@android:color/black"/>

    .
    .
    .

    <TextView
        android:id="@+id/week_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@id/amount_title"
        android:layout_alignTop="@id/amount_title"
        android:layout_alignParentStart="true"
        android:layout_marginStart="5dp"
        android:gravity="center"
        android:padding="5dp"
        android:textAllCaps="true"
        android:text="@string/week"
        android:textColor="@android:color/black"
        android:textSize="20sp" />

    <View
        android:id="@+id/lineSeparator"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_below="@id/week_title"
        android:background="@android:color/darker_gray"/>

    <include
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        layout="@layout/cardview_item"
        android:layout_below="@+id/week_title"
        android:layout_centerHorizontal="true" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我扩展的RecyclerView.Adapter在单独的cardview中显示每个数据集项:

在此输入图像描述

如何使用RecyclerView,CardView和ViewHolder设计模式实现这一点?

任何帮助将不胜感激.

谢谢

bal*_*rkm 1

我最近实现了类似的模式。

具有不同类型布局或每个项目的动态项目数量的 RecyclerView 将存在性能问题,因为我们无法使用 ViewHolder 模式重用视图。

选项 1:使用带有标题的回收器项目布局和动态布局,这将夸大给定的比赛详细信息。但动态布局无法重复使用,因此滚动时会出现明显的滞后。

选项 2:如果您可以决定联赛的最大比赛数,则定义具有最大比赛数的卡片并根据可用的比赛数据隐藏比赛。当与单一动态布局进行比较时,这帮助我提高了性能。

选项 3:结合选项 1 和 2。将静态匹配项与动态项一起使用。仅在需要时使用动态布局。这将最大限度地减少动态布局膨胀的次数。这样你就可以帮助RecyclerView重用视图。

希望对您有帮助。