ItemDecoration for RecyclerView using LinearLayoutManager for Android

Overview

RecyclerItemDecoration

Download Android Arsenal

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

When using recyclerView with different ViewType, you either have only one simple divider or different types of dividers. When you want to draw different dividers between recyclerView's items, basically you must consider items' position; often you need to have separate ItemDecoration's behaviors declared in your code using switch cases or if statements. For example, each time items' position changes happen, you must rewrite ItemDecoration's behaviors.

You don't need to think about items' position! You need to care about their ViewType!!

Image

demo_vertical demo_horizontal

Support

  • LinearLayoutManager
    • Vertical
    • Horizontal
    • Horizontal(Reverse)

Gradle

implementation 'com.github.magiepooh:recycler-itemdecoration:1.1.1@aar'

How To Use

RecyclerView.ItemDecoration decoration = ItemDecorations.vertical(this)
                .first(R.drawable.shape_decoration_green_h_16)
                .type(DemoViewType.LANDSCAPE_TILE.ordinal(), R.drawable.shape_decoration_cornflower_lilac_h_8)
                .type(DemoViewType.LANDSCAPE_ITEM.ordinal(), R.drawable.shape_decoration_gray_h_12_padding)
                .type(DemoViewType.LANDSCAPE_DESCRIPTION.ordinal(), R.drawable.shape_decoration_red_h_8)
                .last(R.drawable.shape_decoration_flush_orange_h_16)
                .create();

recyclerView.addItemDecoration(decoration);

Credit

License

Copyright (C) 2015 magiepooh
Copyright (C) 2013 The Android Open Source Project

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.
Comments
  • Dividers are not drawn.

    Dividers are not drawn.

    Thank you for developing this library! I was looking for the library like this. I tried it on the below condition, but dividers were not drawn.

    Device: Nexus 5(5.1.1) Library: com.android.support:recyclerview-v7:23.1.0, com.github.magiepooh:recycler-itemdecoration:1.1.0@aar, ... Code:

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_main, container, false);
    
        mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    
        mLinearLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
        mRecyclerView.setLayoutManager(mLinearLayoutManager);
    
        RecyclerView.ItemDecoration decoration = ItemDecorations.vertical(getActivity())
                .type(TweetListAdapter.TWEET_TYPE, R.color.divider_color)
                .create();
        mRecyclerView.addItemDecoration(decoration);
    
        mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh);
    
        return view;
    }
    

    XML:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    
        <android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/swipe_refresh"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:enabled="false">
    
            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scrollbarSize="@dimen/scrollbar"
                android:scrollbars="vertical"/>
        </android.support.v4.widget.SwipeRefreshLayout>
    </RelativeLayout>
    
    question 
    opened by mosaicer 3
  • Multiple quality improvements

    Multiple quality improvements

    This pull request is focused on resolving occurrences of Sonar rules squid:S1066 - Collapsible "if" statements should be merged squid:S1319 - Declarations should use Java collection interfaces such as "List" rather than specific implementation classes such as "LinkedList" squid:SwitchLastCaseIsDefaultCheck - "switch" statements should end with a "default" clause pmd:ImmutableField - Immutable Field

    You can find more information about the issues here: https://dev.eclipse.org/sonar/coding_rules#q=squid:S1066 https://dev.eclipse.org/sonar/coding_rules#q=squid:S1319 https://dev.eclipse.org/sonar/coding_rules#q=squid:SwitchLastCaseIsDefaultCheck https://dev.eclipse.org/sonar/coding_rules#q=pmd:ImmutableField

    Please let me know if you have any questions.

    M-Ezzat

    opened by m-ezzat 2
  • Horizontal mode, divider miss (Maybe bug)

    Horizontal mode, divider miss (Maybe bug)

    Horizontal RecyclerView in RecyclerView
    
    // This All right
    RecyclerView.ItemDecoration decoration = ItemDecorations.horizontal(getContext())
                    .first(R.drawable.divider_trans_vertical_4dp)
                    .type(PhotoViewHolder.LAYOUT_ID, R.drawable.divider_trans_vertical_4dp)
                    .last(R.drawable.divider_trans_vertical_4dp)
                    .create();
    
    // Some time some divider are missing, I don't known why.
    RecyclerView.ItemDecoration decoration = ItemDecorations.horizontal(getContext())
                    .type(PhotoViewHolder.LAYOUT_ID, R.drawable.divider_trans_vertical_4dp)
                    .create();
    
    bug 
    opened by kjsolo 1
  • allowBackup Error

    allowBackup Error

    Error:Execution failed for task ':presentation:processDebugManifest'.

    Manifest merger failed : Attribute application@allowBackup value=(false) from AndroidManifest.xml:29:9-36 is also present at [com.github.magiepooh:recycler-itemdecoration:1.1.1] AndroidManifest.xml:12:9-35 value=(true). Suggestion: add 'tools:replace="android:allowBackup"' to element at AndroidManifest.xml:27:5-98:19 to override.

    duplicate 
    opened by kjsolo 1
  • Delete application node in manifest.

    Delete application node in manifest.

    Libraries should not define application node; allowBackup attribute may cause caller get a build error like following:

    Error:Execution failed for task ':app:processDebugManifest'. Manifest merger failed : Attribute application@allowBackup value=(false) from AndroidManifest.xml:77:9-36 is also present at [com.github.magiepooh:recycler-itemdecoration:1.1.1] AndroidManifest.xml:12:9-35 value=(true). Suggestion: add 'tools:replace="android:allowBackup"' to element at AndroidManifest.xml:75:5-520:19 to override.

    Although we can add tools:replace as suggestion, but I think libraries should not define this attribute at all.

    opened by Muyangmin 1
  • Failed to resolve com.github.magiepooh:recycler-itemdecoration:1.1.2

    Failed to resolve com.github.magiepooh:recycler-itemdecoration:1.1.2

    Hi, Im getting this error:

    Error:(25, 13) Failed to resolve: com.github.magiepooh:recycler-itemdecoration:1.1.2 Show in File
    Show in Project Structure dialog

    when trying to put this in the gradle: compile 'com.github.magiepooh:recycler-itemdecoration:1.1.2' I have also tried: compile 'com.github.magiepooh:recycler-itemdecoration:1.1.1' And I have tried to put @aar at the end and I have tried to put maven{...jtpack.io} and still didn't work

    repositories {
            maven {
                url "https://jitpack.io"
            }
        }
    

    Any idea what am I doing wrong? Thanks !

    opened by EricSzla 0
Owner
magiepooh
magiepooh
ItemDecoration for Android Recyclerview

RecyclerView ItemDecorations This project showcases some ItemDecorations for RecyclerViews. There is a blog post about the basics of drawing decoratio

David Medenjak 425 Nov 10, 2022
TikTok-RecyclerView - This is a demo app built using 'Koin' a new dependency injection framework for Android along with RecyclerView and ExoPlayer2.

TikTok-RecyclerView Demo About This is a demo app built using 'Koin' a new dependency injection framework for Android along with RecyclerView and ExoP

Baljeet Singh 19 Dec 28, 2022
ANDROID. ChipsLayoutManager (SpanLayoutManager, FlowLayoutManager). A custom layout manager for RecyclerView which mimicric TextView span behaviour, flow layouts behaviour with support of amazing recyclerView features

ChipsLayoutManager This is ChipsLayoutManager - custom Recycler View's LayoutManager which moves item to the next line when no space left on the curre

Oleg Beloy 3.2k Dec 25, 2022
A RecyclerView that implements pullrefresh and loadingmore featrues.you can use it like a standard RecyclerView

XRecyclerView a RecyclerView that implements pullrefresh , loadingmore and header featrues.you can use it like a standard RecyclerView. you don't need

XRecyclerView 5.3k Dec 26, 2022
A RecyclerView that implements pullrefresh and loadingmore featrues.you can use it like a standard RecyclerView

XRecyclerView a RecyclerView that implements pullrefresh , loadingmore and header featrues.you can use it like a standard RecyclerView. you don't need

XRecyclerView 5.3k Dec 26, 2022
Carousel Recyclerview let's you create carousel layout with the power of recyclerview by creating custom layout manager.

Carousel Recyclerview let's you create carousel layout with the power of recyclerview by creating custom layout manager.

Jack and phantom 504 Dec 25, 2022
RecyclerView : SleepQualityTracker with RecyclerView app

RecyclerView - SleepQualityTracker with RecyclerView app SleepQualityTracker with RecyclerView This app builds on the SleepQualityTracker developed pr

Kevin 2 May 14, 2022
Pagination-RecyclerView - Simple and easy way to Paginating a RecyclerView

Pagination-RecyclerView Simple and easy way to Paginating a RecyclerView Android

Rakshit Nawani 0 Jan 3, 2022
Using RecyclerView to display data instead of ScrollView or lInearLayout for a strong app. It replaces the ScrollView used in trackMySleep app.

RecyclerView - SleepQualityTracker with RecyclerView app This is the toy app for Lesson 7 of the Android App Development in Kotlin course on Udacity.

Espérant GADA 0 Oct 18, 2021
RecyclerView Application example using kotlin and viewbinding.

SimpleRecyclerViewApp Shows how to display some items in a simple list using the RecyclerView and RecycleView.Adapter. The RecycleView is the entity t

Google Developers 2 Mar 28, 2022
An Android Animation library which easily add itemanimator to RecyclerView items.

RecyclerView Animators RecyclerView Animators is an Android library that allows developers to easily create RecyclerView with animations. Please feel

Daichi Furiya 11.2k Jan 8, 2023
A RecyclerView(advanced and flexible version of ListView in Android) with refreshing,loading more,animation and many other features.

UltimateRecyclerView Master branch: Dev branch: Project website:https://github.com/cymcsg/UltimateRecyclerView Description UltimateRecyclerView is a R

MarshalChen 7.2k Jan 2, 2023
[UNMAINTAINED] Sticky Headers decorator for Android's RecyclerView

This project is no longer being maintained sticky-headers-recyclerview This decorator allows you to easily create section headers for RecyclerViews us

timehop 3.7k Jan 8, 2023
[] Super fast and easy way to create header for Android RecyclerView

DEPRECATED I created this library back in the day when I thought RecyclerView was all new and difficult. Writing an adapter that could inflate multipl

Bartek Lipinski 1.3k Dec 28, 2022
Android Library to provide swipe, click and other functionality to RecyclerView

RecyclerViewEnhanced Android Library to provide swipe, click and other functionality to RecyclerView Usage Add this to your build.gradle file dependen

Nikhil Panju 1k Dec 29, 2022
Android library defining adapter classes of RecyclerView to manage multiple view types

RecyclerView-MultipleViewTypeAdapter RecyclerView adapter classes for managing multiple view types Release Note [Release Note] (https://github.com/yqr

Yoshihito Ikeda 414 Nov 21, 2022
Set of plugable extenstions for Android RecyclerView

DynamicRecyclerView Set of light and non-invasive extensions for Android RecyclerView widget. Does not use custom RecyclerView or LayoutManager. With

Ilja S. 342 Nov 11, 2022
Android library for RecyclerView to manage order of items and multiple view types.

recyclerview-binder Android Library for RecyclerView to manage order of items and multiple view types. Features Insert any items to wherever you want

Satoru Fujiwara 185 Nov 15, 2022