简体   繁体   English

CardView中包含的ListView没有显示完整长度

[英]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. 我在cardview内部有一个listview,尽管它的高度设置为wrap_content,但它不能扩展为适合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 ? 如果设置android:minHeight属性呢?

With this you will still have the android:layout_height="wrap_content" but you will also have the minimum height you want to see. 有了这个,您仍然会拥有android:layout_height="wrap_content"但是您还将拥有想要看到的最小高度。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM