如何使用RecyclerView和CardView

Seh*_*oon 3 android android-studio android-cardview android-recyclerview

我在Android开发方面没有太多经验,并尝试在我的应用程序中实现RecyclerView.android studio的版本没有Android L,也没有安装选项.每次它表示android.support.widget.v7.RecyclerView未使用和禁用它来自导入包.我也在Gradle.build的布局文件中给出了参考,但是我的问题仍然有人在帮助吗?

Abh*_*hek 8

按照这一行

  • 材料设计中的CardView和RecyclerView

http://icetea09.com/blog/2014/12/19/android-cardview-and-recyclerview-in-material-design/

将这些添加到依赖项中:

    compile 'com.android.support:cardview-v7:22.2.0'
    compile 'com.android.support:recyclerview-v7:22.2.0'
Run Code Online (Sandbox Code Playgroud)

并更新 gradle

  • 每个例子:

build.gradle

<android.support.v7.widget.CardView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    card_view:contentPadding="16dp"
    card_view:cardElevation="2dp"
    card_view:cardCornerRadius="5dp">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            style="@style/Base.TextAppearance.AppCompat.Headline"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Title" />

        <TextView
            style="@style/Base.TextAppearance.AppCompat.Body1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Content here" />

    </LinearLayout>

</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

RecyclerView:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

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

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)