0

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);

Yes92
  • 301
  • 4
  • 15

2 Answers2

1

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.

Kushan
  • 5,855
  • 3
  • 31
  • 45
0

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

ogulcan
  • 53
  • 1
  • 11