Convert Figma logo to code with AI

yqritc logoRecyclerView-FlexibleDivider

Android library providing simple way to control divider items (ItemDecoration) of RecyclerView

2,400
384
2,400
25

Top Related Projects

Flexbox for Android

A SnapHelper that snaps a RecyclerView to an edge.

8,512

Epoxy is an Android library for building complex screens in a RecyclerView

The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...

"Favor composition over inheritance" for RecyclerView Adapters

An Android Animation library which easily add itemanimator to RecyclerView items.

Quick Overview

RecyclerView-FlexibleDivider is an Android library that provides a simple way to add dividers to RecyclerView items. It offers customizable dividers with various styles, colors, and sizes, allowing developers to easily enhance the visual separation between list items.

Pros

  • Easy integration with existing RecyclerView implementations
  • Highly customizable divider appearance (color, size, padding, etc.)
  • Supports both horizontal and vertical dividers
  • Allows for complex divider patterns, including different styles for specific items

Cons

  • Limited to RecyclerView only, not applicable to other list views
  • May require additional configuration for complex layouts
  • Potential performance impact on large lists with complex divider patterns
  • Not actively maintained (last update was in 2018)

Code Examples

  1. Basic usage with default divider:
RecyclerView.addItemDecoration(
    HorizontalDividerItemDecoration.Builder(context).build()
)
  1. Customizing divider color and size:
RecyclerView.addItemDecoration(
    HorizontalDividerItemDecoration.Builder(context)
        .color(Color.RED)
        .sizeResId(R.dimen.divider_height)
        .build()
)
  1. Using a custom drawable as divider:
RecyclerView.addItemDecoration(
    HorizontalDividerItemDecoration.Builder(context)
        .drawable(R.drawable.custom_divider)
        .build()
)
  1. Applying different dividers based on item position:
RecyclerView.addItemDecoration(
    HorizontalDividerItemDecoration.Builder(context)
        .paintProvider(object : PaintProvider {
            override fun dividerPaint(position: Int, parent: RecyclerView): Paint? {
                return when {
                    position % 2 == 0 -> Paint().apply { color = Color.RED }
                    else -> Paint().apply { color = Color.BLUE }
                }
            }
        })
        .build()
)

Getting Started

  1. Add the dependency to your build.gradle file:
dependencies {
    implementation 'com.yqritc:recyclerview-flexibledivider:1.4.0'
}
  1. Apply the divider to your RecyclerView:
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration

// In your Activity or Fragment
recyclerView.addItemDecoration(
    HorizontalDividerItemDecoration.Builder(this)
        .color(Color.GRAY)
        .sizeResId(R.dimen.divider_height)
        .marginResId(R.dimen.divider_margin)
        .build()
)

This setup adds a basic gray divider with custom height and margin to your RecyclerView. Adjust the parameters as needed for your specific use case.

Competitor Comparisons

Flexbox for Android

Pros of flexbox-layout

  • Provides a more flexible and powerful layout system, allowing for complex arrangements of child views
  • Supports both horizontal and vertical layouts, as well as wrapping
  • Officially maintained by Google, ensuring long-term support and updates

Cons of flexbox-layout

  • Steeper learning curve due to its more complex nature and numerous configuration options
  • May introduce unnecessary complexity for simple divider use cases
  • Potentially higher performance overhead for basic layouts

Code Comparison

RecyclerView-FlexibleDivider:

new HorizontalDividerItemDecoration.Builder(this)
    .color(Color.RED)
    .size(5)
    .margin(20, 20)
    .build();

flexbox-layout:

FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(context);
layoutManager.setFlexDirection(FlexDirection.ROW);
layoutManager.setJustifyContent(JustifyContent.FLEX_START);
recyclerView.setLayoutManager(layoutManager);

Summary

RecyclerView-FlexibleDivider is a simpler, more focused library for adding customizable dividers to RecyclerViews. It's easier to implement for basic divider needs but lacks advanced layout capabilities.

flexbox-layout offers a comprehensive layout system inspired by CSS Flexbox, providing greater flexibility and control over item positioning. While more powerful, it may be overkill for simple divider requirements and requires more setup and configuration.

Choose RecyclerView-FlexibleDivider for straightforward divider implementation, and flexbox-layout for complex, flexible layouts beyond simple item separation.

A SnapHelper that snaps a RecyclerView to an edge.

Pros of GravitySnapHelper

  • Provides smooth snapping behavior for RecyclerView items
  • Supports multiple gravity options (start, top, end, bottom, center)
  • Easy integration with existing RecyclerView implementations

Cons of GravitySnapHelper

  • Limited to snapping functionality, doesn't provide divider customization
  • May require additional setup for complex layouts or custom item decorations

Code Comparison

GravitySnapHelper:

RecyclerView recyclerView = findViewById(R.id.recyclerView);
SnapHelper snapHelper = new GravitySnapHelper(Gravity.START);
snapHelper.attachToRecyclerView(recyclerView);

RecyclerView-FlexibleDivider:

RecyclerView recyclerView = findViewById(R.id.recyclerView);
recyclerView.addItemDecoration(
    new HorizontalDividerItemDecoration.Builder(this)
        .color(Color.RED)
        .sizeResId(R.dimen.divider)
        .build());

Summary

GravitySnapHelper focuses on providing smooth snapping behavior for RecyclerView items, offering various gravity options for alignment. It's easy to integrate but limited to snapping functionality.

RecyclerView-FlexibleDivider, on the other hand, specializes in customizing dividers between RecyclerView items. It offers extensive options for divider appearance and positioning but doesn't provide snapping capabilities.

Choose GravitySnapHelper for smooth item snapping and alignment, or RecyclerView-FlexibleDivider for advanced divider customization. For projects requiring both functionalities, consider using them in combination.

8,512

Epoxy is an Android library for building complex screens in a RecyclerView

Pros of Epoxy

  • More comprehensive solution for building complex RecyclerViews
  • Supports data binding and view holders out of the box
  • Offers automatic diffing and efficient updates

Cons of Epoxy

  • Steeper learning curve due to its complexity
  • Requires more setup and boilerplate code
  • May be overkill for simpler RecyclerView implementations

Code Comparison

RecyclerView-FlexibleDivider:

RecyclerView.addItemDecoration(
    new HorizontalDividerItemDecoration.Builder(this)
        .color(Color.RED)
        .size(5)
        .margin(20, 20)
        .build());

Epoxy:

class MyEpoxyController : EpoxyController() {
    override fun buildModels() {
        header {
            id("header")
            title("My List")
        }
        items.forEach { item ->
            itemView {
                id(item.id)
                title(item.title)
            }
        }
    }
}

RecyclerView-FlexibleDivider focuses solely on adding customizable dividers to RecyclerViews, making it simpler to use for this specific purpose. Epoxy, on the other hand, provides a more comprehensive solution for building and managing complex RecyclerViews, offering features like automatic diffing and efficient updates. While Epoxy requires more setup and has a steeper learning curve, it offers greater flexibility and power for handling complex list structures. The choice between the two depends on the specific needs of your project and the complexity of your RecyclerView implementations.

The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...

Pros of FastAdapter

  • More comprehensive solution for RecyclerView adapters, offering features beyond just dividers
  • Supports multiple view types and complex list structures
  • Actively maintained with frequent updates and a large community

Cons of FastAdapter

  • Steeper learning curve due to its extensive feature set
  • May be overkill for simple list implementations
  • Larger library size compared to RecyclerView-FlexibleDivider

Code Comparison

FastAdapter:

val fastAdapter = FastAdapter.with(itemAdapter)
recyclerView.adapter = fastAdapter
itemAdapter.add(Item("Example"))

RecyclerView-FlexibleDivider:

recyclerView.addItemDecoration(
    FlexibleDividerDecoration.Builder(this)
        .sizePx(1)
        .color(Color.BLACK)
        .build()
)

FastAdapter provides a more comprehensive solution for managing RecyclerView adapters, offering features like multi-selection, dragging, and filtering. It's suitable for complex list structures but may be excessive for simple implementations. RecyclerView-FlexibleDivider, on the other hand, focuses solely on providing flexible divider options for RecyclerViews. It's lightweight and easy to implement for basic divider needs but lacks the advanced features of FastAdapter.

The code comparison shows that FastAdapter requires setting up an adapter and adding items, while RecyclerView-FlexibleDivider is implemented as an item decoration, demonstrating their different approaches to enhancing RecyclerViews.

"Favor composition over inheritance" for RecyclerView Adapters

Pros of AdapterDelegates

  • Provides a more flexible and scalable approach for handling multiple view types in RecyclerView adapters
  • Encourages better separation of concerns and modular design in complex list implementations
  • Supports easier addition and removal of new view types without modifying existing code

Cons of AdapterDelegates

  • Requires more initial setup and boilerplate code compared to RecyclerView-FlexibleDivider
  • May introduce additional complexity for simple list implementations with few view types
  • Learning curve for developers unfamiliar with the delegate pattern

Code Comparison

AdapterDelegates:

class CatAdapterDelegate : AdapterDelegate<List<DisplayableItem>>() {
    override fun isForViewType(items: List<DisplayableItem>, position: Int): Boolean {
        return items[position] is Cat
    }
    // ... other methods
}

RecyclerView-FlexibleDivider:

RecyclerView.addItemDecoration(
    new HorizontalDividerItemDecoration.Builder(this)
        .color(Color.RED)
        .sizeResId(R.dimen.divider)
        .marginResId(R.dimen.leftmargin, R.dimen.rightmargin)
        .build());

AdapterDelegates focuses on managing multiple view types, while RecyclerView-FlexibleDivider specializes in customizing dividers between list items. The choice between the two depends on the specific requirements of your RecyclerView implementation.

An Android Animation library which easily add itemanimator to RecyclerView items.

Pros of recyclerview-animators

  • Offers a wide range of pre-built animations for RecyclerView items
  • Supports custom animations for adding, removing, and moving items
  • Easy to implement with minimal code changes

Cons of recyclerview-animators

  • Focused solely on animations, lacking divider customization options
  • May introduce performance overhead for complex animations on large lists
  • Requires additional configuration for combining animations with other RecyclerView features

Code Comparison

RecyclerView-FlexibleDivider:

RecyclerView.ItemDecoration divider = new HorizontalDividerItemDecoration.Builder(this)
    .color(Color.RED)
    .sizeResId(R.dimen.divider)
    .marginResId(R.dimen.leftmargin, R.dimen.rightmargin)
    .build();
recyclerView.addItemDecoration(divider);

recyclerview-animators:

RecyclerView.ItemAnimator animator = new SlideInLeftAnimator();
animator.setAddDuration(300);
animator.setRemoveDuration(300);
recyclerView.setItemAnimator(animator);

RecyclerView-FlexibleDivider focuses on customizing dividers between items, offering extensive options for appearance and positioning. In contrast, recyclerview-animators specializes in adding smooth animations to RecyclerView items, enhancing the visual appeal of list interactions. While RecyclerView-FlexibleDivider provides more control over item separation, recyclerview-animators excels in creating dynamic and engaging list experiences through various animation types.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

RecyclerView-FlexibleDivider

Android Arsenal License Download

Android library providing simple way to control divider items of RecyclerView

Simple Divider Complex Divider

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());
ItemDecorationUsage
HorizontalDividerItemDecorationFor layout manager having vertical orientation to draw horizontal divider
VerticalDividerItemDecorationFor 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.