如果还不会使用RecyclerView,请看我的另一篇博客
RecyclerView不像ListView那样自带分割线,需要自定义分割线
先在drawable中创建一个line_divider.xml文件用户设置分割线的颜色
android:shape="rectangle"
>
android:width="1dp"
android:height="1dp" />
自定义RecyclerView.ItemDecoration类的子类SimpleDividerItemDecoration类,代码如下:
public class SimpleDividerItemDecoration extends RecyclerView.ItemDecoration {
private Drawable mDivider; //分割线Drawable
private int mDividerHeight; //分割线高度
private int inset; //分割线缩进值
/**
* 使用line_divider中定义好的颜色
*
* @param context
* @param dividerHeight 分割线高度
*/
public SimpleDividerItemDecoration(Context context, int dividerHeight) {
mDivider = ContextCompat.getDrawable(context, R.drawable.line_divider);
mDivi