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.1.0'
}

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"
    />

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.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 nightwolf738 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
Jack and phantom
Arc Layout is a view group with which you can add a arc-shaped container in your layout.

ArcLayout Arc Layout is a view group with which you can add a arc-shaped container in your layout. Two main variables are the direction and the curvat

Ali Rezaiyan 32 Aug 17, 2022
Example mod with Mixin to help you to get started with creating a mod with mixins.

ExampleMixinMod Example mod with Mixin to help you to get started with creating a mod with mixins. For usage of mixins, see here. Also, remember to tu

null 0 Dec 16, 2021
A simple and easy adapter for RecyclerView. You don't have to make adapters and view holders anymore. Slush will help you.

ํ•œ๊ตญ์–ด No more boilerplate adapters and view holders. Slush will make using RecyclerView easy and fast. The goal of this project is to make RecyclerView,

SeungHyun 26 Sep 13, 2022
๐Ÿ‘‹ A common toolkit (utils) โš’๏ธ built to help you further reduce Kotlin boilerplate code and improve development efficiency. Do you think 'kotlin-stdlib' or 'android-ktx' is not sweet enough? You need this! ๐Ÿญ

Toolkit [ ?? Work in progress โ› ?? ??๏ธ ?? ] Snapshot version: repositories { maven("https://s01.oss.sonatype.org/content/repositories/snapshots") }

ๅ‡› 35 Jul 23, 2022
A library for creating dynamic skeleton view

Skeleton Placeholder View Overview A Library designed to draw a Skeleton by "skinning" the view from a provided layout. Skeleton is composed of Bone w

Ferry Irawan 25 Jul 20, 2021
An example of a test task for creating a simple currency converter application for the Android platform. The app is developed using Kotlin, MVI, Dagger Hilt, Retrofit, Jetpack Compose.

Simple Currency Converter Simple Currency Converter Android App by Isaev Semyon An example of a test task for creating a simple currency converter app

Semyon Isaev 1 Nov 8, 2021
Framework for quickly creating connected applications in Kotlin with minimal effort

Ktor is an asynchronous framework for creating microservices, web applications and more. Written in Kotlin from the ground up. import io.ktor.server.n

ktor.io 10.7k Jan 9, 2023
Survey-service - Application for creating online surveys and polls

Survey Service Application for creating online surveys and polls Functionality A

Anatoly Babushkin 2 Apr 6, 2022
Kotlin library for creating long running connections using MQTT protocol

About Courier Courier is a kotlin library for creating long running connections using MQTT protocol. Long running connection is a persistent connectio

Gojek 92 Dec 23, 2022
With MaterialTimelineView you can easily create a material looking timeline.

MaterialTimelineView With MaterialTimelineView you can easily create a material looking timeline. Setup The library is pushed to jCenter() as an AAR,

Przemek 454 Dec 19, 2022
A Kotlin work manager library for Android with progress notifications and Hilt support.

Boot Laces A kotlin work manager library for Android that includes notifications and Hilt support. User Instructions Add the JitPack repository to you

Chris Basinger 35 Oct 8, 2022
Location Service Manager for Kotlin Multiplatform Mobile iOS and android

Location Service Manager for Kotlin Multiplatform Mobile iOS and android Features Provides simple permission settings Dramatically reduce the amount o

LINE 55 Dec 10, 2022
An easy to use package manager for Fabric Minecraft mods.

pacmc pacmc is a package manager for Fabric Minecraft mods. The aim of this project is to massively reduce the effort you have to put in to installing

Jakob K 109 Dec 30, 2022
Android Ad Manager Works with Admob, Mopup, Facebook- Bidding and Audience Networks

AndroidAdManager Works with Admob, Mopup, Facebook- Bidding and Audience Networks. Added ad types are NativeBanner, NativeAdvanced, Interstitial and B

Hashim Tahir 11 May 18, 2022
Strong-bax - An open source password manager project

What is strong-bax? Strong-bax is an open source password manager project. Stron

null 1 Feb 6, 2022
๐Ÿ› ๏ธ The missing drawable toolbox for Android. Create drawables programmatically and get rid of the boring and always repeated drawable.xml files.

DrawableToolbox English | ไธญๆ–‡ The missing DrawableToolbox for Android. Create drawables programmatically and get rid of the boring and always repeated

Hong Duan 1.1k Jan 4, 2023
Create kotlin android project with one line of command.

README This is an android application template project built with kotlin language and some useful libraries. It provides a creator script to quickly c

nekocode 1.6k Dec 20, 2022
Create minecraft worlds without lag!

WorldGen ๋ž™ ์—†๋Š” ์›”๋“œ ์ƒ์„ฑ์„ ์œ„ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‹œ์ž‘ํ•˜๊ธฐ์— ์•ž์„œ, ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” UHC_System ์˜ ์›”๋“œ ์ƒ์„ฑ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋ฉด์„œ WorldCreator์˜ ๋‹จ์ ์ธ ๋ž™์„ ์—†์• ๊ธฐ ์œ„ํ•ด ๋งŒ๋“ค์–ด์ง„ ์ฝ”๋“œ์˜ ์ผ๋ถ€๋ฅผ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๊ณต๊ฐœํ•˜๋Š” ๊ฒƒ์ž„์„ ์•Œ๋ ค๋“œ๋ฆฝ๋‹ˆ๋‹ค WorldCre

dolphin2410 4 Jul 29, 2022