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

Overview

Carousel Recyclerview

Create carousel effect in recyclerview with the CarouselRecyclerview in a simple way.


Build Status License License License AndroidWeekly


Layout manager

Including in your project

Maven Central with version prefix filter CarouselRecyclerview

Gradle

Add below codes to your root build.gradle file (not your module build.gradle file).

allprojects {
    repositories {
            mavenCentral()
    }
}

And add a dependency code to your module's build.gradle file.

dependencies {
   implementation 'com.github.sparrow007:carouselrecyclerview:1.2.1'
}

Usage

Basic Example for Kotlin

Here is a basic example of implementing carousel recyclerview in koltin files (activity or fragment) with attribute.

  val carouselRecyclerview = findViewById<CarouselRecyclerview>(R.id.recycler)
  carouselRecyclerview.adapter = adapter

Basic Example for XML

Here is a basic example of implementing carousel recyclerview in layout xml.

">
<com.jackandphantom.carouselrecyclerview.CarouselRecyclerview
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:id="@+id/recycler"/>
Property infinite and 3D on Item enabled Property infinite and alpha on Item enabled

API Methods

Method Description Default
fun set3DItem(is3DItem: Boolean) Make the view tilt according to their position, middle position does not tilt. false
fun setInfinite(isInfinite: Boolean) Create the loop of the given view means there is no start or end, but provided position in the interface will be correct. false
fun setFlat(isFlat: Boolean) Make the flat layout in the layout manager of the reyclerview false
fun setAlpha(isAlpha: Boolean) Set the alpha for each item depends on the position in the layout manager false
fun setIntervalRatio(ratio: Float) Set the interval ratio which is gap between items (views) in layout manager 0.5f (value of gap, it should in range (0.4f - 1f))
fun getCarouselLayoutManager(): CarouselLayoutManager Get the carousel layout manager instance
fun getSelectedPosition(): Int Get selected position from the layout manager center view Positoin

API Methods Usage

val carouselRecyclerview = findViewById<CarouselRecyclerview>(R.id.recycler)
      carouselRecyclerview.adapter = adapter
      carouselRecyclerview.set3DItem(true)
      carouselRecyclerview.setInfinite(true)
      carouselRecyclerview.setAlpha(true)
      carouselRecyclerview.setFlat(true)
      val carouselLayoutManager = carouselRecyclerview.getCarouselLayoutManager()
      val currentlyCenterPosition = carouselRecyclerview.getSelectedPosition()

Item Position Listener

You can listen to the position whenever the scroll happens you will get notified about the position, following are codes for listener

 carouselRecyclerview.setItemSelectListener(object : OnSelected {
          override fun onItemSelected(position: Int) {
              //Cente item
          }
      })

Reflection ImageView

You see in the demo that there is a mirror image (reflection imageview), for this i already created custom imageview for this.

Use ReflectionImageView in xml layout and provide src

">
 <com.jackandphantom.carouselrecyclerview.view.ReflectionImageView
     android:layout_width="120dp"
     android:layout_height="120dp"
     android:scaleType="fitXY"
     android:src="@drawable/hacker"
    />

Reflection Layout

Now you can show reflection in more efficient way and 3x faster than ReflectionImageView see the codes below

">
xml version="1.0" encoding="utf-8"?>
<com.jackandphantom.carouselrecyclerview.view.ReflectionViewContainer
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android"
    app:reflect_relativeDepth="0.5"
    app:reflect_gap="0dp"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    >
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/guypro"
        android:scaleType="fitXY"
        android:id="@+id/image" />
com.jackandphantom.carouselrecyclerview.view.ReflectionViewContainer>

Notes about Reflection imageview

I would recommend you to use image loading library like Glide for loading image in reflection image for better performance


What's New Version 1.2.1 🎉 🎉

Bugs Fix (ScrollToPosition)

Version 1.2.0

Adding reflection container

Version 1.1.0

Adding Support for orientation changes

Contribute 🤝

If you like the project and somehow wants to contribute, you are welcome to contribute by either submitting issues, refactor, pull request Thankyou.

Find this repository useful? ❤️

Support it by joining stargazers for this repository.
And follow me for next creation 🤩

License

Copyright 2021 Sparrow007 (Ankit kumar)

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
  • CarouselRecyclerView not scrolling to given position

    CarouselRecyclerView not scrolling to given position

    Hi there,

    I have to dynamically scroll the recycler view to a given positon, unlikely when i use rv.scrollToPosition(givenPosition) the app crashes. Following the error : " Caused by: kotlin.UninitializedPropertyAccessException: lateinit property recycler has not been initialized at com.jackandphantom.carouselrecyclerview.CarouselLayoutManager.scrollToPosition(CarouselLayoutManager.kt:404)".

    Really hope someone out there can help me. Thanks a lot

    opened by totomft1518 13
  •  java.lang.ArithmeticException: divide by zero in version 1.2.2

    java.lang.ArithmeticException: divide by zero in version 1.2.2

    java.lang.ArithmeticException: divide by zero at com.jackandphantom.carouselrecyclerview.CarouselLayoutManager.onSelectedCallback(CarouselLayoutManager.kt:543) at com.jackandphantom.carouselrecyclerview.CarouselLayoutManager.access$onSelectedCallback(CarouselLayoutManager.kt:17) at com.jackandphantom.carouselrecyclerview.CarouselLayoutManager$startScroll$2.onAnimationEnd(CarouselLayoutManager.kt:383) at android.animation.Animator$AnimatorListener.onAnimationEnd(Animator.java:554) at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1250) at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1492) at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:146) at android.animation.AnimationHandler.access$100(AnimationHandler.java:37) at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:54) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:970) at android.view.Choreographer.doCallbacks(Choreographer.java:796) at android.view.Choreographer.doFrame(Choreographer.java:727) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:250) at android.app.ActivityThread.main(ActivityThread.java:7848) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)

    bug 
    opened by Serafin-Lopez 11
  • Added alternative for ImageReflectionView with enhanced ReflectionVie…

    Added alternative for ImageReflectionView with enhanced ReflectionVie…

    Implemented a custom linear layout to show reflection of the view contained in it. Feature 👍🏾 10x faster load time than ReflectionImageView Matches the view draw in real time.

    opened by snehilrx 8
  • setItemSelectlistener will not work when changing adapter with setting alpha

    setItemSelectlistener will not work when changing adapter with setting alpha

    if(selectedTeam=="homeTeam") { adapter = carousalViewAdapter( homePlayerList!!, basketballData.getTeams[0].colors[0] ) carouselRecyclerview.adapter = adapter carouselRecyclerview.set3DItem(false) setIntervalRatio(0.7f) carouselRecyclerview.setAlpha(true) carouselRecyclerview.setInfinite(false) } else { adapter = carousalViewAdapter( awayTeamPlayerList!!, basketballData.getTeams[1].colors[0] ) carouselRecyclerview.adapter = adapter carouselRecyclerview.set3DItem(false) setIntervalRatio(0.7f) carouselRecyclerview.setAlpha(true) carouselRecyclerview.setInfinite(false) }

    In this case ItemSelectListener will only work when all property settings are removed. property will change each time when we set adapter also

    opened by arjunbabuc 3
  • java.lang.ArithmeticException: divide by zero

    java.lang.ArithmeticException: divide by zero

    It's stable crash on scrolling, probably when re-assign items and adapter on scrolling animation.

    java.lang.ArithmeticException: divide by zero at com.jackandphantom.carouselrecyclerview.CarouselLayoutManager.onSelectedCallback(CarouselLayoutManager.kt:543) at com.jackandphantom.carouselrecyclerview.CarouselLayoutManager.access$onSelectedCallback(CarouselLayoutManager.kt:17) at com.jackandphantom.carouselrecyclerview.CarouselLayoutManager$startScroll$2.onAnimationEnd(CarouselLayoutManager.kt:383) at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1149) at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1309) at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:146) at android.animation.AnimationHandler.-wrap2(AnimationHandler.java) at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:54) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:869) at android.view.Choreographer.doCallbacks(Choreographer.java:683) at android.view.Choreographer.doFrame(Choreographer.java:616) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

    opened by Andrew0000 2
  • New Feature: Vertical CarouselRecyclerView 🚀

    New Feature: Vertical CarouselRecyclerView 🚀

    WORK

    • Fix #7
    • Made necessary changes where X coordinates are used
    • As using both directions requires more lines of code, I refactored those parts making them reusable
    • Not suitable for ReflectionViewContainer as it is also vertical oriented custom view

    DEMO

    demo

    enhancement 
    opened by egemenhamutcu 1
  • Removing an item causes NullPointerException

    Removing an item causes NullPointerException

    When an item is removed from the backing dataset and adapter is notified via notifyItemRemoved method, demo app crashes with NullPointerException.

    • Add method to DataAdapter and call it within MainActivity
        fun removeData() {
            // remove last item for test purposes
            val orgListSize = list.size
            this.list = this.list.subList(0, orgListSize - 1).toList()
            notifyItemRemoved(orgListSize - 1)
        }
    
    • App crashes with the following exception log
    E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.jackandphantom.carousellayout, PID: 28559
        java.lang.NullPointerException
            at com.jackandphantom.carouselrecyclerview.CarouselLayoutManager.getChildActualPos(CarouselLayoutManager.kt:468)
            at com.jackandphantom.carouselrecyclerview.CarouselRecyclerview.getChildDrawingOrder(CarouselRecyclerview.kt:106)
            at android.view.ViewGroup.getAndVerifyPreorderedIndex(ViewGroup.java:2134)
            at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4351)
            at android.view.View.draw(View.java:22670)
            at androidx.recyclerview.widget.RecyclerView.draw(RecyclerView.java:4429)
            at android.view.View.updateDisplayListIfDirty(View.java:21491)
            at android.view.View.draw(View.java:22377)
            at android.view.ViewGroup.drawChild(ViewGroup.java:4595)
            at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4354)
            at android.view.View.updateDisplayListIfDirty(View.java:21482)
            at android.view.View.draw(View.java:22377)
            at android.view.ViewGroup.drawChild(ViewGroup.java:4595)
            at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4354)
            at android.view.View.updateDisplayListIfDirty(View.java:21482)
            at android.view.View.draw(View.java:22377)
            at android.view.ViewGroup.drawChild(ViewGroup.java:4595)
            at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4354)
            at android.view.View.updateDisplayListIfDirty(View.java:21482)
            at android.view.View.draw(View.java:22377)
            at android.view.ViewGroup.drawChild(ViewGroup.java:4595)
            at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4354)
            at android.view.View.updateDisplayListIfDirty(View.java:21482)
            at android.view.View.draw(View.java:22377)
            at android.view.ViewGroup.drawChild(ViewGroup.java:4595)
            at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4354)
            at android.view.View.updateDisplayListIfDirty(View.java:21482)
            at android.view.View.draw(View.java:22377)
            at android.view.ViewGroup.drawChild(ViewGroup.java:4595)
            at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4354)
            at android.view.View.draw(View.java:22670)
            at com.android.internal.policy.DecorView.draw(DecorView.java:826)
            at android.view.View.updateDisplayListIfDirty(View.java:21491)
            at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:559)
            at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:565)
            at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:642)
            at android.view.ViewRootImpl.draw(ViewRootImpl.java:4372)
            at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:4077)
            at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3335)
            at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2135)
            at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8636)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1035)
            at android.view.Choreographer.doCallbacks(Choreographer.java:858)
            at android.view.Choreographer.doFrame(Choreographer.java:789)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1020)
            at android.os.Handler.handleCallback(Handler.java:938)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:236)
            at android.app.ActivityThread.main(ActivityThread.java:8045)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
    
    opened by burcsade 1
  • Add support to enable/disable scrolling in recyclerview

    Add support to enable/disable scrolling in recyclerview

    Adds support to enable/disable the scrolling of the recycler view by using the setIsScrollingEnabled method of the CarouselLayoutManager.

    carouselLayoutManager.setIsScrollingEnabled(false)

    opened by mattiasrosberg 1
  • How to Implement Adapter ??

    How to Implement Adapter ??

    @sparrow007 glad to see this awsm library Sir... But I have some doubt related to its adapter, so do I need to use a normal adapter or this library has some sort of in build adapter class ??

    opened by KapilYadav-dev 1
  • App getting crashed

    App getting crashed

    java.lang.ArithmeticException: divide by zero at com.jackandphantom.carouselrecyclerview.CarouselLayoutManager.onSelectedCallback(CarouselLayoutManager.kt:543) at com.jackandphantom.carouselrecyclerview.CarouselLayoutManager.access$onSelectedCallback(CarouselLayoutManager.kt:17) at com.jackandphantom.carouselrecyclerview.CarouselLayoutManager$startScroll$2.onAnimationEnd(CarouselLayoutManager.kt:383) at android.animation.Animator$AnimatorListener.onAnimationEnd(Animator.java:554) at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1242) at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1484) at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:146) at android.animation.AnimationHandler.access$100(AnimationHandler.java:37) at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:54) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1161) at android.view.Choreographer.doCallbacks(Choreographer.java:986) at android.view.Choreographer.doFrame(Choreographer.java:894) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1148) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7697) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

    opened by akashmi 0
  • Cannot change spacing between items if isFlat = true

    Cannot change spacing between items if isFlat = true

    For our design we need to use the isFlat mode, but the forced 1.1f spacing is too much. It would be awesome if even with isFlat we could set 0.1f or other values to setIntervalRatio.

    opened by kiskunk 0
  • Divide by zero crash when calling notifydatasetchanged during scroll animation

    Divide by zero crash when calling notifydatasetchanged during scroll animation

    java.lang.ArithmeticException: divide by zero at com.jackandphantom.carouselrecyclerview.CarouselLayoutManager.onSelectedCallback(CarouselLayoutManager.kt:559)

    selectedPosition = abs(selectedPosition % itemCount)

    Example for reproducing the issue:

    1. Have a carousel recyclerview in a layout under SwipeRefreshLayout
    2. Use the SwipeRefreshLayout to load the list items using notifydatasetchanged on the adapter while the carousel is inbetween 2 items

    Tried invalidation, canceling animations, removing all views - to no avail.

    opened by kiskunk 1
  • Adapter.notifyItemChanged(int) causes it to crash

    Adapter.notifyItemChanged(int) causes it to crash

        java.lang.NullPointerException
            at com.jackandphantom.carouselrecyclerview.CarouselLayoutManager.getChildActualPos(CarouselLayoutManager.kt:468)
            at com.jackandphantom.carouselrecyclerview.CarouselRecyclerview.getChildDrawingOrder(CarouselRecyclerview.kt:106)
            at android.view.ViewGroup.getAndVerifyPreorderedIndex(ViewGroup.java:1733)
            at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3510)
            at android.view.View.draw(View.java:17192)
            at androidx.recyclerview.widget.RecyclerView.draw(RecyclerView.java:4429)
            at android.view.View.updateDisplayListIfDirty(View.java:16171)
            at android.view.View.draw(View.java:16955)
    ...
    
    opened by mice777 4
Releases(1.2.6)
Owner
Jack and phantom
I am a code lover person and Android Engineer @Decathlon
Jack and phantom
Custom Layout Manager for Recycler View

Circular Layout Manager Overview A library for Android which essentially contains a Custom Layout Manager for Recycler View which lays out its child v

Kapilesh Iyer 181 Dec 2, 2022
A layout manager for the RecyclerView with interchangeable linear, grid, and staggered displays of views, all with configurable section headers including the sticky variety as specified in the material design docs.

SuperSLiM This is the version 5 development branch. Project Plan Support me on Patreon Blog What is Version 5 Version 5 is the current development bra

Tonic Artos 2.1k Jan 2, 2023
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
Handy library to integrate pagination, which allow no data layout, refresh layout, recycler view in one view and easy way to bind pagination in app.

Pagination View Handy library to integrate pagination, which allow no data layout, refresh layout, recycler view in one view and easy way to bind pagi

DhiWise 4 Dec 18, 2021
[] 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
Simple plug and play custom RecyclerView

InfiniteScrollRecyclerView Pros: Simple plug and play custom RecyclerView. Easy to use Built on top of RecyclerView, hence it is performant as it work

Frontier 61 Dec 28, 2022
ItemDecorator - Custom item decorator for adding divider for only the first item of a RecyclerView

ItemDecorator Custom item decorator for adding divider for only the first item o

null 1 Apr 1, 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
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
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
A RecyclerView Adapter which allows you to have an Infinite scrolling list in your apps

Infinite Recycler View A RecyclerView Adapter which allows you to have an Infinite scrolling list in your apps. This library offers you a custom adapt

IB Sikiru 26 Dec 10, 2019
Square Cycler API allows you to easily configure an Android RecyclerView declaratively in a succinct way.

Square Cycler – a RecyclerView API The Square Cycler API allows you to easily configure an Android RecyclerView declaratively in a succinct way. Desig

Square 791 Dec 23, 2022
An adapter to create Android RecyclerViews with sections, providing headers and footers.

⚠ This library is no longer maintained ⚠️ SectionedRecyclerView An adapter to create Android RecyclerViews with sections, providing headers and footer

Tomás Ruiz-López 809 Dec 21, 2022
Dividers is a simple Android library to create easy separators for your RecyclerViews

Dividers Dividers is an Android library to easily create separators for your RecyclerViews. It supports a wide range of dividers from simple ones, tha

Karumi 490 Dec 28, 2022
Simple lib to create a endless recycler view scroll

Endless RecyclerView A simple lib to create an infinite list in a RecyclerView. When you reach the end of the list, a callback is triggered, where you

Jaison Klemer 4 Sep 2, 2022
A custom recycler view with shimmer views to indicate that views are loading.

ShimmerRecyclerView Intro A custom recycler view with shimmer views to indicate that views are loading. The recycler view has a built-in adapter to co

Harish Sridharan 3.8k Dec 31, 2022
Examples of custom recycler view items. Automatically detecting a dominant color of an image using Picasso and Palette libraries

custom-image-list-item Examples of custom RecyclerView items using Data Binding Features: Loading images urls with the help of a Picasso library Autom

Alina Stepanova 2 Sep 12, 2022