【问题标题】:ListView contained in a CardView is not showing full lengthCardView 中包含的 ListView 未显示完整长度
【发布时间】:2016-01-15 05:19:23
【问题描述】:

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

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

【问题讨论】:

  • 将高度设置为 match_parent
  • 为什么你使用cardview作为listview
  • 您找到解决方案了吗?

标签: android android-layout android-listview android-cardview android-cards


【解决方案1】:

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

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

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多