Cardview 是全部进入一张卡片

Cardview is all goes into one card

我已经使用 CardView 制作应用程序,但我的 cardview 将进入一张卡片。

我的代码:

recyclerview_activity.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:padding="16dp"
    >

    <android.support.v7.widget.RecyclerView
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:id="@+id/rv"
        >

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


</LinearLayout>

I get something like this

我认为唯一的问题是您 CardViews 之间的差距。你一定不能在 CardView 中让 CompatPadding 为真,这就是为什么看起来数据被组合成一个 CardView 尝试使其为真。 使用以下代码应该可以工作:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/cv"
    card_view:cardCornerRadius="5dp"
    card_view:cardUseCompatPadding="true"
    android:foreground="?android:attr/selectableItemBackground"
>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="16dp"
    >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/person_photo"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="16dp"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/person_name"
        android:layout_toRightOf="@+id/person_photo"
        android:layout_alignParentTop="true"
        android:textSize="30sp"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/person_age"
        android:layout_toRightOf="@+id/person_photo"
        android:layout_below="@+id/person_name"
        />

</RelativeLayout>

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