RecyclerViewDecoration

Introduction: a common tool class for itemdecoration of RecyclerView,support ninepatch image.
More: Author   ReportBugs   
Tags:

a common tool class for decoration of RecyclerView,support ninepatch image.

中文版

Release Note

You can import this lib with gradle or maven because it exists on JCenter.

More expandable useful methods will be shown in ExpandRecyclerView lib. This lib will be combine into ExpandRecyclerView lib.
If you don't want to use ExpandRecyclerView lib, no worry, you can still use this lib.

gradle

compile 'com.arjinmc.android:recyclerviewdecoration:3.1'

maven

<dependency>
  <groupId>com.arjinmc.android</groupId>
  <artifactId>recyclerviewdecoration</artifactId>
  <version>3.1</version>
  <type>pom</type>
</dependency>

RecyclerViewItemDecoration.Builder

Param thickness would be better when it's an even number which can be divided by 2.

Horizonal Mode


rvData.setLayoutManager(new LinearLayoutManager(context
  , LinearLayoutManager.VERTICAL,false));
rvData.addItemDecoration(new RecyclerViewItemDecoration.Builder(context)
        .color(Color.RED)
        .color("#ff0000")
        .dashWidth(8)
        .dashGap(5)
        .thickness(6)
        .drawableID(R.drawable.diver)
        .drawableID(R.drawable.diver_color_no)
        .paddingStart(20)
        .paddingEnd(10)
        .firstLineVisible(true)
        .lastLineVisible(true)
        .ignoreTypes(int[])
        .create());

Vertical Mode


rvData.setLayoutManager(new LinearLayoutManager(context
  , LinearLayoutManager.HORIZONTAL,false));
rvData.addItemDecoration(new RecyclerViewItemDecoration.Builder(this)
       .color(Color.RED)
       .color("#ff0000")
       .dashWidth(8)
       .dashGap(5)
       .thickness(6)
       .drawableID(R.drawable.diver_vertical)
       .drawableID(R.drawable.diver_v)
       .paddingStart(20)
       .paddingEnd(10)
       .firstLineVisible(true)
       .lastLineVisible(true)
       .ignoreTypes(int[])
       .create());

Grid Mode


rvData.setLayoutManager(new GridLayoutManager(this, 6));
rvData.addItemDecoration(new RecyclerViewItemDecoration.Builder(this)
       .color(Color.RED)
       .color("#ff0000")
       .dashWidth(8)
       .dashGap(5)
       .thickness(6)
       .drawableID(R.drawable.diver_color_no)
       .gridBottomVisible(true) //control bottom border
       .gridTopVisible(true) //control top border
       .gridLeftVisible(true) //control left border
       .gridRightVisible(true) //control right border
       .create());

When you use gridHorizontalSpacing or gridVerticalSpacing or both,thickness is required especially if need to show borders.Currently these two new attributes donot support image or ninepatch.There is a sample.

rvData.setLayoutManager(new GridLayoutManager(this, 6));
rvData.addItemDecoration(new RecyclerViewItemDecoration.Builder(this)
       .color("#ff0000")
       .dashWidth(8)
       .dashGap(5)
       .thickness(6)
       .gridBottomVisible(true) //control bottom border
       .gridTopVisible(true) //control top border
       .gridLeftVisible(true) //control left border
       .gridRightVisible(true) //control right border
       .gridHorizontalSpacing(20)
       .gridVerticalSpacing(10)
       .create());

RecyclerViewSpaceItemDecoration

rvData.setLayoutManager(new GridLayoutManager(this, 6));
rvData.addItemDecoration(new RecyclerViewSpaceItemDecoration.Builder(this)
      //if horizontal and vertical spacing is the same size,just use margin(int size)
      //if recyclerview is LinearLayout,use margin(int size)
//      .margin(10)
        .marginHorizontal(10)
        .marginVertical(20)
        .ignoreTypes(int[])
        .create());

RecyclerViewStickyHeadItemDecoration

//Default group view type is zero, you can change it. Support any RecyclerView Adapter.
rvList.addItemDecoration(new RecyclerViewStickyHeadItemDecoration.Builder().groupViewType(0).create());

RecyclerViewStickyHeadItemDecoration reference to https://github.com/chenpengfei88/StickyItemDecoration

sample images

image
image image image

Apps
About Me
Google+: Trinea trinea
GitHub: Trinea