Giter VIP home page Giter VIP logo

recyclerviewdivider's Introduction

RecyclerViewDivider

Build Status

A RecyclerView's divider that can be customized with simple properties or advanced ones.

It supports completely LinearLayoutManager, GridLayoutManager and partially StaggeredGridLayoutManager.

Usage

If you want to use the basic version of this divider you can just add this line of code after your setAdapter() method:

RecyclerViewDivider.with(context).build().addTo(recyclerView);

Customization

All dividers in the app have default values in xml resources:

  • Color → R.color.recycler_view_divider_color (default is #CFCFCF)
  • Size → R.dimen.recycler_view_divider_size (default is 1dp)
  • Margin size → R.dimen.recycler_view_divider_margin_size (default is 0dp)

It can be customized in code with properties equals for each divider:

  • color(int) → change color
  • drawable(Drawable) → change drawable
  • tint(int) → change drawables' tint
  • size(int) → change height for an horizontal divider, width for a vertical one
  • marginSize(int) → change left/right margin for an horizontal divider, top/bottom for a vertical one
Example with all general properties set:
RecyclerViewDivider.with(context)
                .color(color)
                // OR
                .drawable(drawable)
                .tint(tint)
                .size(size)
                .marginSize(marginSize)
                .hideLastDivider()
                .build()
                .addTo(recyclerView);

It can also use custom factories to have a different logic for each divider:

  • visibilityFactory(VisibilityFactory) → set visibility
  • drawableFactory(DrawableFactory) → set color/drawable
  • tintFactory(TintFactory) → set tint
  • sizeFactory(SizeFactory) → set size
  • marginFactory(MarginFactory) → set margin
Example with all factories set:
RecyclerViewDivider.with(context)
                .visibilityFactory(new VisibilityFactory() {
                    @Override
                    public int displayDividerForItem(int groupCount, int groupIndex) {
                        if (groupCount % groupIndex == 0) {
                            return SHOW_ITEMS_ONLY;
                        }
                        return SHOW_ALL;
                    }
                })
                .drawableFactory(new DrawableFactory() {
                    @Override
                    public Drawable drawableForItem(int groupCount, int groupIndex) {
                        return position % 2 == 0 ? new ColorDrawable(Color.BLACK) : new ColorDrawable(Color.BLUE);
                    }
                })
                .tintFactory(new TintFactory() {
                    @Override
                    public int tintForItem(int groupCount, int groupIndex) {
                        return position == 0 ? Color.YELLOW : Color.GRAY;
                    }
                })
                .sizeFactory(new SizeFactory() {
                    @Override
                    public int sizeForItem(@Nullable Drawable drawable, int orientation, int groupCount, int groupIndex) {
                        return position % 2 == 0 ? 45 : 78;
                    }
                })
                .marginFactory(new MarginFactory() {
                    @Override
                    public int marginSizeForItem(int groupCount, int groupIndex) {
                        return position % 2 == 0 ? 10 : 10 * 2;
                    }
                })
                .build()
                .addTo(recyclerView);

You can also use this divider as a simple space between RecyclerView's items:

Example of divider as space:
RecyclerViewDivider.with(context).asSpace().build().addTo(recyclerView);

Compatibility

Android SDK: RecyclerViewDivider requires a minimum API level of 9

Integration

You can download a jar from GitHub's releases page or grab it from jcenter() or mavenCentral().

Gradle

dependencies {
    compile 'com.github.fondesa:recycler-view-divider:1.3.3'
}

Maven

<dependency>
  <groupId>com.github.fondesa</groupId>
  <artifactId>recycler-view-divider</artifactId>
  <version>1.3.3</version>
  <type>pom</type>
</dependency>

recyclerviewdivider's People

Contributors

fondesa avatar

Watchers

James Cloos avatar Android Guru 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.