现在来介绍两种控件recyclerview和cardview,并通过实例将它们结合在一起实现一种横向卡片式滑动效果.
1.recyclerview
recyvlerview是android sdk 新增加的一种控件,也被官方推荐代替listview来使用,因为其具有更好的灵活性和代替性。
2.cardview
cardview是安卓5.0推出的一种卡片式控件,内部封装了许多有用的方法来实现美观效果。
3.如何使用recylerview和cardview在android studio中
在build.gradle中添加依赖再编辑即可
compile 'com.android.support:recyclerview-v7:25.+'
compile 'com.android.support:cardview-v7:25
4.通过实例,使用两种控件实现横向卡片式滑动效果
建立main.xml布局文件,代码如下:
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recycler_view"
>
使用过listview的同学应该知道还需要一个子布局来填充recyclerview
以下为recyclerview_item.xml的代码:
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recyclerview_item"
android:padding="30dp"
>
android:layout_width="match_parent"
android:layout_height="match_parent"
<