RecyclerView-FlexibleDivider


Source link: https://github.com/yqritc/RecyclerView-FlexibleDivider

RecyclerView-FlexibleDivider

Android library providing simple way to control divider items of RecyclerView

Release Note

[Release Note] ( https://github.com/yqritc/RecyclerView-FlexibleDivider/releases)

Gradle

repositories {

  jcenter() 
}
  dependencies {

  compile 'com.yqritc:recyclerview-flexibledivider:1.4.0' 
}

Usage

The following is the simplest usage.
Drawing a divider drawable retrieved from android.R.attr.listDivider between each cell.

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
 recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this).build());
ItemDecoration Usage
HorizontalDividerItemDecoration For layout manager having vertical orientation to draw horizontal divider
VerticalDividerItemDecoration For layout manager having horizontal orientation to draw vertical divider
*Please note that you can only set one of above item decorations at a time.

If you want to set color, size and margin values, you can specify as the followings.

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
 recyclerView.addItemDecoration(

new HorizontalDividerItemDecoration.Builder(this)

  .color(Color.RED)

  .sizeResId(R.dimen.divider)

  .marginResId(R.dimen.leftmargin, R.dimen.rightmargin)

  .build());

Instead of setting color and size, you can set paint object.

Paint paint = new Paint();
 paint.setStrokeWidth(5);
 paint.setColor(Color.BLUE);
 paint.setAntiAlias(true);
 paint.setPathEffect(new DashPathEffect(new float[]{
25.0f, 25.0f
}
, 0));
 recyclerView.addItemDecoration(

new HorizontalDividerItemDecoration.Builder(this).paint(paint).build());

Also 9patch drawable can be used for drawing divider.

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
 recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this)

.drawable(R.drawable.sample)

.size(15)

.build());

If you want to customize divider depending on the position, implement the following interfaces.

List of provider

The following providers can be implemented and controllable for each divider drawn between cells.
Please refer to ComplexAdapter class in the sample for the usage of providers in detail.

  • ColorProvider Provide color for divider

  • PaintProvider Provide paint object for divider line to draw.

  • DrawableDivider Provide drawable object for divider line

  • SizeProvider Provide height for horizontal divider, width for vertical divider.

  • VisibilityProvider
    Enables you to control the visibility of dividers.

  • MarginProvider for horizontal divider (vertical list)
    Enables you to specify left and right margin of divider.

  • MarginProvider for vertical divider (horizontal list)
    Enables you to specify top and bottom margin of divider.

For GridLayoutManager, the position parameter of above providers is group index of items. So, control your divider based on [group index]( http://developer.android.com/intl/ja/reference/android/support/v7/widget/GridLayoutManager.SpanSizeLookup.html#getSpanGroupIndex(int, int)) instead of the position of items.

Optional

  • Builder.showLastDivider
    Draw divider line at the end of last item in RecyclerView. If you enable this, the range of position parameter of providers listed above is 0 to itemCount-1. Otherwise, the range is 0 to itemCount-2.

  • Builder.positionInsideItem
    Draw divider inside items.
    If you want to follow material design guideline, enable this feature.

Note

  • When neither of color, paint, drawable is set, default divider retrieved from android.R.attr.listDivider will be used.
  • When you set Paint, you must use setColor and setStrokeWidth methods of paint class.
  • If you want to use DashPathEffect, please note the following issue. https://code.google.com/p/android/issues/detail?id=29944
Looking for custom ItemDecoration to achieve equal column space for GridLayoutManager?

Check out https://gist.github.com/yqritc/ccca77dc42f2364777e1

License

Copyright 2016 yqritc  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

Easy way to handle shared preferences.

A wrapper for sending/receiving messages and data changes between Android Wear and Android Mobile.

RecyclerItemDecoration allows you to draw divider between items in recyclerview with multiple ViewType without considering items' positions!

A loading animation based on Floating Action Button.

Android LINQ is a small subset of collection manipulation utilities inspired by Microsoft C# LINQ library and targeted at Android developers looking to use new Java 8 Stream() API.

Customizable Calendar Widget for Android.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes