I have the following screen basket_fragment.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/basket_fragment_recycler_view" android:layout_width="match_parent" android:layout_height="wrap_content"> </android.support.v7.widget.RecyclerView> </LinearLayout>
RecyclerView contains CardView which in its. the queue is set in this way basket_card_view.xml:
<android.support.v7.widget.CardView android:id="@+id/basket_fragment_card_view" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" <!--this 200 dp!-->> android:layout_margin="8dp" android:elevation="6dp" app:cardBackgroundColor="@android:color/white" app:cardCornerRadius="8dp"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp"> <TextView android:id="@+id/basket_fragment_card_view_text_view_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Recipe Name" android:textSize="20sp" android:textStyle="bold"/> <ListView android:id="@+id/basket_fragment_card_view_list_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_below="@+id/basket_fragment_card_view_text_view_title" android:choiceMode="multipleChoice"> </ListView> </RelativeLayout> </android.support.v7.widget.CardView>
The problem is that only one item from the ListView displayed.
If you strictly define the size of CardView , for example android:layout_height="200dp" , then the list items are displayed (as high as possible).
How to get rid of this problem and make it so that the size of the card ( CardView ) depended on the internal filling ( wrap_content ) taking into account the number of elements?
UPD . Maybe I'm wrong in terms of choosing a widget to display a list of lines with checkboxes (that is, in this case, for example, it would be more rational to use dynamic addition of elements to, for example, some LinearLayout in the code itself), but I still have some problem