RecyclerView

RecyclerView 增加分割線

1.添加默認的分割線

recyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));

2.自定義分割線

添加自定義樣式到Drawable下

 <?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="rectangle">

 <gradient
     android:centerColor="#00ff00" //綠色
     android:endColor="#0000ff"    //藍色
     android:startColor="#ff0000"  //紅色
     android:type="linear" />
 <size android:height="3dp" />
</shape>

調用

DividerItemDecoration divider = new DividerItemDecoration(this,DividerItemDecoration.VERTICAL);
//設置自定義樣式
divider.setDrawable(ContextCompat.getDrawable(this,R.drawable.custom_divider));
//添加到recyclerView上
recyclerView.addItemDecoration(divider);

發表迴響