Android: how can I insert a RecyclerView inside CardView?

前端 未结 2 1240
野的像风
野的像风 2020-12-25 08:20

The activity I am talking about must show a RecyclerView populated by CardViews as items. My goal is to show in every CardView a RecyclerView in its turn.<

相关标签:
2条回答
  • 2020-12-25 09:03

    As of support library 23.2, the LayoutManager API brings auto-measurement which allows a RecyclerView to size itself based on the size of its contents. This means that using WRAP_CONTENT for a dimension of the RecyclerView, are now possible. You’ll find all built in LayoutManagers now support auto-measurement.

    Source

    0 讨论(0)
  • 2020-12-25 09:04

    I faced the exact same problem. You have to specify the layout height of the RecyclerView inside the CardView. Change it from wrap_content to a specific value in dp. Nested RecyclerView doesnt wrap the content in its height if the parent scrolling is VERTICAL and similarly doesnt wrap the content in its width when the parent scrolling is HORIZONTAL.

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/card_analysis"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/activity_vertical_margin"
    android:layout_marginBottom="@dimen/activity_vertical_margin" 
    android:layout_marginLeft="@dimen/activity_horizontal_margin"
    android:layout_marginRight="@dimen/activity_horizontal_margin"
    android:padding="5dp"
    card_view:cardCornerRadius="5dp" >
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/item_mode"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:paddingTop="5dp"
            android:paddingLeft="@dimen/activity_horizontal_margin" >
    
        </android.support.v7.widget.RecyclerView>
    </LinearLayout>
    </android.support.v7.widget.CardView>
    
    0 讨论(0)
提交回复
热议问题