添加默认的分割线
//添加Android自带的分割线
recyclerView.addItemDecoration(new DividerItemDecoration(MainActivity.this,DividerItemDecoration.VERTICAL));
自定义分割线
1、创建shape.xml文件
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:centerColor="#ff0000"
//设置颜色
android:endColor="#ff0000"
android:startColor="#ff0000"
android:type="linear" />
<size android:height="3dp" />
</shape>
2、添加自定义分割线
//添加自定义分割线
DividerItemDecoration divider = new DividerItemDecoration(ClassRoomActivity.this,DividerItemDecoration.VERTICAL);
divider.setDrawable(ContextCompat.getDrawable(ClassRoomActivity.this,R.drawable.divider));
recyclerView.addItemDecoration(divider);
注意:这种只适用于列表布局(LinearLayout)的RecyclerView