将ListView转换为CardView

将ListView转换为CardView,listview,android-listview,android-appcompat,android-cardview,Listview,Android Listview,Android Appcompat,Android Cardview,我有一个运行新Appcompat V21的应用程序,还有一个带有基本列表视图的主活动。是否可以将此基本列表视图转换为每张卡片上都有图像和标题的卡片视图?(例如,使用Google+应用程序)您需要使用带有自定义适配器的recyclerView。是的,实际上很容易做到这一点。由于您已经在使用支持库的v21,您可以将基本列表项代码包装到CardView中。像这样的 <?xml version="1.0" encoding="utf-8"?> <android.support.v7.w

我有一个运行新Appcompat V21的应用程序,还有一个带有基本列表视图的主活动。是否可以将此基本列表视图转换为每张卡片上都有图像和标题的卡片视图?(例如,使用Google+应用程序)

您需要使用带有自定义适配器的recyclerView。

是的,实际上很容易做到这一点。由于您已经在使用支持库的v21,您可以将基本列表项代码包装到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:layout_gravity="center"
    card_view:cardCornerRadius="4dp"
    card_view:contentPadding="8dp">

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

        <TextView
            android:id="@+id/title"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/image"
            android:gravity="center_vertical"
            android:text="Example application"/>
    </RelativeLayout>
</android.support.v7.widget.CardView>