如何使用RecyclerView和CardView [英] How to use RecyclerView and CardView
问题描述
我在android开发方面经验不足,因此尝试在我的应用程序中实现RecyclerView. android studio版本没有Android L,也没有安装选项.每次在未使用android.support.widget.v7.RecyclerView
时说,并从导入软件包中禁用它.我也在Gradle.build中提供布局文件的引用,但是我的问题仍然存在,有人可以帮忙吗?
I don't have much experience in android development and try to implement RecyclerView in my application. The version of android studio does not have Android L neither there is option to install. Everytime it says android.support.widget.v7.RecyclerView
in not used and disabled it from import packages. I give refrences in layout file also in Gradle.build but my problem is still there anyone help please?
推荐答案
关注此行
- 材料设计中的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'
并更新模块build.gradle
- 每个示例:
CardView
CardView
<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>
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>
这篇关于如何使用RecyclerView和CardView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!