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
Kotlin way of building RecyclerView Adapter 🧩. You do not have to write RecyclerView Adapters again and again and suffer from handling of different view types. Kiel will help you.

Kiel Kiel is a RecyclerView.Adapter with a minimalistic and convenient Kotlin DSL which provides utility on top of Android's normal RecyclerView.Adapt

ibrahim yilmaz 370 Jan 2, 2023
. Android library that integrate sticky section headers in your RecyclerView

recyclerview-stickyheaders Recyclerview-stickyheaders is an Android library that makes it easy to integrate section headers in your RecyclerView. Thes

null 968 Nov 10, 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 5, 2023
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
[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 Dec 31, 2022
Pumped up RecyclerView

##Description This is an attempt to make RecyclerView easier to use. Features built in: ProgressBar while adapter hasn't been set EmptyView if adapter

Anton Malinskiy 2.6k Jan 5, 2023
A very easy-to-use and non-intrusive implement of Swipe to dismiss for RecyclerView.

RecyclerViewSwipeDismiss A very easy-to-use and non-intrusive implement of Swipe to dismiss for RecyclerView. Preview How to use Add these lines to yo

xcodebuild 431 Nov 23, 2022
An adapter which could be used to achieve a parallax effect on RecyclerView.

android-parallax-recycleview Integration Step 1. Add the JitPack repository to your build file repositories { maven { url "https://jitpack

Pedro Oliveira 1.6k Nov 17, 2022
A Fast Scroller for the RecyclerView world!

RecyclerViewFastScroller The RecyclerViewFastScroller is a widget that can be added to a layout and connected to a RecyclerView for fast scrolling. Th

Daniel Smith 1.1k Dec 19, 2022
*** WARNING: This library is no longer maintained *** An easy way to add a simple 'swipe-and-do-something' behavior to your `RecyclerView` items. Just like in Gmail or Inbox apps.

SwipeToAction An easy way to add a simple 'swipe-and-do-something' behavior to your RecyclerView items. Just like in Gmail or Inbox apps. Integration

Victor Calvello 223 Nov 16, 2022
RecyclerView extension library which provides advanced features. (ex. Google's Inbox app like swiping, Play Music app like drag and drop sorting)

Advanced RecyclerView This RecyclerView extension library provides Google's Inbox app like swiping, Play Music app like drag-and-drop sorting and expa

Haruki Hasegawa 5.2k Dec 23, 2022
Android library to display a ListView whose cells are not rigid but flabby and react to ListView scroll.

FlabbyListView This library is not maintained anymore and there will be no further releases Android library to display a ListView which cells are not

JPARDOGO 762 Nov 23, 2022
An Android custom ListView and ScrollView with pull to zoom-in.

PullZoomView An Android custom ListView and ScrollView with pull to zoom-in. Features Set ZoomView enable Add HeaderView Custom ZoomView Parallax or N

Frank-Zhu 2.3k Dec 26, 2022
An android library for section headers that stick to the top

StickyListHeaders StickyListHeaders is an Android library that makes it easy to integrate section headers in your ListView. These section headers stic

Emil Sjölander 5.5k Jan 2, 2023
Android library to achieve in an easy way, the behaviour of the home page in the Expedia app, with a pair of auto-scroll circular parallax ListViews.

ListBuddies This library is not maintained anymore and there will be no further releases Android library of a pair of auto-scroll circular parallax Li

JPARDOGO 970 Dec 29, 2022
Android library to observe scroll events on scrollable views.

Android-ObservableScrollView Android library to observe scroll events on scrollable views. It's easy to interact with the Toolbar introduced in Androi

Soichiro Kashima 9.6k Dec 29, 2022
Android ListView that mimics a GridView with asymmetric items. Supports items with row span and column span

AsymmetricGridView An Android custom ListView that implements multiple columns and variable sized elements. Please note that this is currently in a pr

Felipe Lima 1.8k Jan 7, 2023
Drag and drop GridView for Android

DynamicGrid Drag and drop GridView for Android. Depricated It's much better to use solutions based on recycler view. For example https://github.com/h6

Alex Askerov 920 Dec 2, 2022
An Android staggered grid view which supports multiple columns with rows of varying sizes.

AndroidStaggeredGrid ##Notice - Deprecated - 09-2015 This library has been deprecated. We will no longer be shipping any updates or approving communit

Etsy, Inc. 4.8k Dec 29, 2022