一个CardView中有多个RecyclerView项

5

我试图创建与这个应用程序相同的多个RecyclerView项,每个CardView项中有:

enter image description here

我已经创建了一个包含数据集项(例如此示例中的比赛)的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>

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

enter image description here

如何使用RecyclerView、CardView和ViewHolder设计模式实现这个功能?

任何帮助都将不胜感激。

谢谢


我也想做同样的事情,但是还是想不出来。你有解决方案吗?请与我分享。 - riseres
2
我找到了这个链接。https://github.com/gabrielemariotti/cardslib/blob/master/doc/CARDWITHLIST.md#using-a-custom-inner-layout - riseres
1个回答

1

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

对于一个具有不同类型布局或每个项目动态数量的RecyclerView,由于无法使用ViewHolder模式重用视图,因此会出现性能问题。

选项1:使用recycler item layout和动态布局,以填充给定的比赛细节。但是,动态布局无法被重复使用,所以在滚动时会出现明显的延迟。

选项2:如果您可以确定联赛的最大比赛数量,则定义一个具有最大比赛数量并根据可用比赛数据隐藏比赛的卡片。与单个动态布局相比,这有助于提高性能。

选项3:结合选项1和2。使用静态匹配项目和动态项目。仅在需要时使用动态布局。这将最小化动态布局被膨胀的次数。从而帮助RecyclerView重用视图。

希望它能对你有所帮助。


请问您能否发布布局设计? - Sushrita

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接