1

我在卡片视图中有一个列表视图,虽然它设置为 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>

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

4

1 回答 1

2

如果你设置一个android:minHeight属性呢?

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

希望能帮助到你。

于 2016-01-15T07:37:54.103 回答