简体   繁体   中英

Recycler view inside Card view

I'm trying to add a ryclerview inside a cardview in order to have a list of items inside a card. The problem is that the list inside the card is now not scrollable.
Here's my code:

 <android.support.v7.widget.CardView
        android:id="@+id/card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/records"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="8dp" />

    </android.support.v7.widget.CardView>

I tried to change the layout_width and height, with no results and to set recyclerView.setHasFixedSize(true);

I assume you want to use card view for just visual reasons( elevation etc.). In that case you can customize recycler view to look like card view instead of using inside of it. There are some examples for that link

Your card view height is wrap content and so is your recycler's. This will cause the card view to have the same height as your recycler view.

Thus it will always be as big as the list and this there will never be any scrolling. Try changing card views height to match_parent

If your card view is also inside a another scrolling layout, make the outer most layout where you add the card view to a NestedScrollView. And in this case do not change the card view height to match parent. Keep it wrap content.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM