GithubHelp home page GithubHelp logo

lukemi / recyclerviewdecoration Goto Github PK

View Code? Open in Web Editor NEW

This project forked from arjinmc/recyclerviewdecoration

0.0 2.0 0.0 307 KB

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

License: Apache License 2.0

Java 100.00%

recyclerviewdecoration's Introduction

RecyclerViewDecoration

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

Attention please!

Some people ask me for RecyclerViewDecoration doesnot work for the orientation attributes of LinearLayout. No,it doesn't. Because RecyclerViewDecoration has its own orientation attributes as itself drawn orientation, not the same as orientation attributes of LinearLayout.

Update News

2017/7/3rd

  • optimize draw lines for grid mode.
  • remove old methods that deprecated.
  • add two new attributes gridHorizontalSpacing and gridVerticalSpacing for grid mode with pure or gap lines.

2017/5/27th

  • add compatible method to compatible with support v7 LayoutManager.

If you don't understand the orientation of this RecyclerViewItemDecoration common tool class,just use builder.parent(recycelerView) instead of builder.mode(orientaion), it can automatic compatible with the layoutmanager of RecyclerView.

2017/5/23rd

  • add gridBottomVisible,gridTopVisible,gridLeftVisible,gridRightVisible params for MODE_GRID. You can control the borders' visibility of grid mode,it's up to you make them shown or hidden(default is hidden).
  • optimizate algorithm.

2017/4/15th

  • add Builder for RecyclerViewItemDecoration to create.
  • add params paddingStart and paddingEnd for MODE_HORIZONTAL and MODE_VERTICAL.
  • add params firstLineVisible and lastLineVisible for MODE_HORIZONTAL and MODE_VERTICAL.

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)
        //default mode is RecyclerViewItemDecoration.HORIZONTAL
        .mode(RecyclerViewItemDecoration.HORIZONTAL) //or parent(rvData)
        .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)
        .create());

Vertical Mode

rvData.setLayoutManager(new LinearLayoutManager(context
  , LinearLayoutManager.HORIZONTAL,false));
rvData.addItemDecoration(new RecyclerViewItemDecoration.Builder(this)
       .mode(RecyclerViewItemDecoration.MODE_VERTICAL) //or parent(rvData)
       .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)
       .create());

Grid Mode

rvData.setLayoutManager(new GridLayoutManager(this, 6));
rvData.addItemDecoration(new RecyclerViewItemDecoration.Builder(this)
       .mode(RecyclerViewItemDecoration.MODE_GRID) //or parent(rvData)
       .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)
       .mode(RecyclerViewItemDecoration.MODE_GRID) //or parent(rvData)
       .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());

sample images

image
image image image

recyclerviewdecoration's People

Contributors

arjinmc avatar

Watchers

James Cloos avatar LukeMi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.