Cardview全部进入一张卡片

时间:2016-07-11 18:47:21

标签: java android android-recyclerview android-cardview android-cards

我已经使用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

1 个答案:

答案 0 :(得分:1)

I think the only issue is with the gap between your CardViews. You must not be having CompatPadding true in CardView thats why it looks like the data is clubbed into one CardView try making it true. Use following code it should work :

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