最近自己想写一个购物类App 所以就模仿着网易严选的样式去写 今天刚好也写到分类这一块 看着这样的样式前面自己是想用两个LIstView去完成 后面想了想打算用 RecyclerView写 ,然后在百度上找了一些dome 。其实网上也有很多人写了这样的文章 自己为什么要写呢 第一自己写的话可以加深自己的理解第二如果哪天用到了可以直接来自己的博客上找
好了 其他也不做说明 下面看看我写出来的效果图
在使用RecyclerView 要在gradle上添加
compile 'com.android.support:design:25.1.1'
首先我们使用的是 两个RecyclerView所以我们的布局是这样子的如果你使用的 linearLayout 布局的话记得加上android:orientation="horizontal"
<android.support.v7.widget.RecyclerView android:id="@+id/classify_left_list" android:layout_width="@dimen/two_fifty_six" android:layout_height="match_parent" android:layout_weight="1" android:background="@color/white" android:scrollbars="none" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:layout_weight="2"> <ImageView android:id="@+id/series_image" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:src="@mipmap/star_pager" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:textSize="@dimen/twenty_four" android:text="-- 列表 --"/> <android.support.v7.widget.RecyclerView android:id="@+id/classify_right_list" android:layout_width="match_parent" android:layout_height="wrap_content" android:scrollbars="none" /> </LinearLayout>在接下来就是编写两个Adapter了 首先我们来写左边这个
public class ClassifyLeftAdapter extends RecyclerView.Adapter { private Context mContext;