5

Tôi đang cố gắng để tạo ra nhiều mục RecyclerView trong mỗi mục CardView như ứng dụng này không:Nhiều mặt hàng RecyclerView trong một CardView

enter image description here

tôi đã tạo ra một cardview_item.xml chứa chi tiết dữ liệu (các phù hợp trong ví dụ này)

và thẻ cardview_title.xml chứa tiêu đề của thẻ (giải đấu trong ví dụ này).

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> 

Các RecyclerView.Adapter mà tôi mở rộng cho thấy mỗi mục dữ liệu trong cardview riêng biệt:

enter image description here

Làm thế nào tôi có thể thực hiện điều này với RecyclerView Mẫu CardView và ViewHolder?

Mọi trợ giúp sẽ được đánh giá cao.

Cảm ơn

+0

Tôi muốn thực hiện tương tự. Nhưng vẫn không thể hình dung được. Bạn có giải pháp? Hãy chia sẻ với tôi. – riseres

+2

Tôi tìm thấy liên kết này. https://github.com/gabrielemariotti/cardslib/blob/master/doc/CARDWITHLIST.md#using-a-custom-inner-layout – riseres

Trả lời

1

Gần đây, tôi đã triển khai một mẫu tương tự.

Một RecyclerView có loại bố cục khác nhau hoặc số mục động cho từng mục sẽ có vấn đề về hiệu suất vì chúng tôi không thể sử dụng lại chế độ xem với mẫu ViewHolder.

Tùy chọn 1: Sử dụng bố cục vật phẩm tái chế với tiêu đề và bố cục động sẽ làm tăng chi tiết trận đấu đã cho. Tuy nhiên, bố cục động không thể được tái sử dụng và vì vậy bạn sẽ có được độ trễ có thể nhìn thấy trong khi bạn cuộn.

Tùy chọn 2: Nếu bạn có thể quyết định số lượng đối sánh tối đa cho giải đấu thì hãy xác định thẻ có số lượng kết quả phù hợp nhất và ẩn các kết quả phù hợp theo dữ liệu đối sánh có sẵn. Điều này đã giúp tôi cải thiện hiệu suất khi bạn so sánh nó với bố cục động duy nhất.

Tùy chọn 3: Kết hợp tùy chọn 1 và 2. Sử dụng các mục phù hợp tĩnh cùng với một mục động. Chỉ sử dụng bố cục động khi cần. Điều này sẽ giảm thiểu số lần bố cục động sẽ bị thổi phồng. Vì vậy, bạn có thể giúp RecyclerView sử dụng lại chế độ xem.

Hy vọng nó sẽ giúp bạn.

+0

bạn có thể vui lòng đăng thiết kế bố cục không – Sushrita

Các vấn đề liên quan