CardView 中包含的 ListView 未显示全长

ListView contained in a CardView is not showing full length

我在卡片视图中有一个列表视图,虽然它的高度设置为 wrap_content,但它不会扩展以适应列表视图的完整大小。它只显示第一项。

<?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>

如果我为卡片的高度设置一个明确的大小,它会起作用,但这没有用,因为列表视图的大小会经常改变。有没有办法让卡片正确显示整个列表视图?

如果设置 android:minHeight 属性呢?

有了这个你仍然会有 android:layout_height="wrap_content" 但你也会有你想要看到的最小高度。

希望对您有所帮助。