1.先创建一个xml文件,名称随便,例如:divide_gray_ten.xml 内容如下:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> //矩形 <solid android:color="#0000ff" /> <size android:height="10dp" /> </shape>
2.在代码中如下操作即可
LinearLayoutManager layoutManager = new LinearLayoutManager(this); recyclerView.setLayoutManager(layoutManager); DividerItemDecoration decor = new DividerItemDecoration(this, layoutManager.getOrientation()); decor.setDrawable(ContextCompat.getDrawable(this,R.drawable.divide_gray_ten)); //这里在就是 recyclerView.addItemDecoration(decor);
3.运行代码看看效果吧!