简体   繁体   中英

ListView contained in a CardView is not showing full length

I have a listview inside of a cardview, and although the height it set to wrap_content, it doesn't expand to fit the full size of the listview. It only displays the first item.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:id="@+id/rootCardView"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#FEFEFE"
android:layout_margin="8dp">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/textPrimary"
        android:textSize="20sp"
        android:textStyle="bold"
        android:layout_alignParentTop="true"
        android:id="@+id/card_title"
        android:layout_marginTop="16dp"
        android:layout_marginStart="16dp"/>

    <!-- Main ListView -->
    <ListView
        android:id="@+id/cardsList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="none"
        android:layout_below="@+id/card_title">
    </ListView>
</RelativeLayout>


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

It works if I set a definite size for the height of the card, but that isn't useful as the listview size will change often. Is there any way to have the card correctly show the whole listview?

What about if you set a android:minHeight attribute ?

With this you will still have the android:layout_height="wrap_content" but you will also have the minimum height you want to see.

Hope it helps.

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