Setting divider for RecyclerView.
-
Add the dependencies to your build.gradle file, RecyclerViewDivider is avaiable in JCenter:
compile 'com.jaeger.recyclerviewdivider:library:1.0.1'
-
Use
RecyclerViewDivider.Builder
RecyclerViewDivider divider = new RecyclerViewDivider.Builder(this) .setStyle(RecyclerViewDivider.Style.BETWEEN) .setDrawableRes(R.drawable.divider) .setMarginLeft(72) .setMarginRight(8) .build(); mRvList.addItemDecoration(divider);
-
Style
- START
- END
- BETWEEN
- BOTH
-
Set margin
RecyclerViewDivider divider = new RecyclerViewDivider.Builder(this) .setOrientation(RecyclerViewDivider.VERTICAL) .setStyle(RecyclerViewDivider.Style.BETWEEN) .setColorRes(R.color.divider_gray) .setSize(1.5f) .setMarginLeft(72) .setMarginRight(8) .build();
-
Set drawable
RecyclerViewDivider divider = new RecyclerViewDivider.Builder(this) .setStyle(RecyclerViewDivider.Style.BETWEEN) .setDrawableRes(R.drawable.divider) .setMarginLeft(72) .setMarginRight(8) .build(); mRvList.addItemDecoration(divider);
-
Set skip count
RecyclerViewDivider divider = new RecyclerViewDivider.Builder(this) .setOrientation(RecyclerViewDivider.VERTICAL) .setStyle(RecyclerViewDivider.Style.BETWEEN) .setColorRes(R.color.divider_gray) .setSize(1.5f) .setStartSkipCount(2) .setMarginLeft(72) .setMarginRight(8) .build();