{"id":22828573,"url":"https://github.com/sultanayubi360/discretescrollview_library","last_synced_at":"2026-04-29T00:03:07.061Z","repository":{"id":266621405,"uuid":"898858394","full_name":"SultanAyubi360/DiscreteScrollView_Library","owner":"SultanAyubi360","description":"A scrollable list of items that centers the current element and provides easy-to-use APIs for cool item animations.","archived":false,"fork":false,"pushed_at":"2025-01-22T10:52:11.000Z","size":7568,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-06T06:34:15.912Z","etag":null,"topics":["android","android-library","android-studio","carousel","carousel-slider","discrete-scroll","item-picker","layoutmanager","page-transformations","swipe","view","viewpager","viewpager2"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SultanAyubi360.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-05T07:04:37.000Z","updated_at":"2025-01-22T10:52:14.000Z","dependencies_parsed_at":"2025-01-21T12:33:47.398Z","dependency_job_id":null,"html_url":"https://github.com/SultanAyubi360/DiscreteScrollView_Library","commit_stats":null,"previous_names":["sultanayubi360/discretescrollview_library"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SultanAyubi360%2FDiscreteScrollView_Library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SultanAyubi360%2FDiscreteScrollView_Library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SultanAyubi360%2FDiscreteScrollView_Library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SultanAyubi360%2FDiscreteScrollView_Library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SultanAyubi360","download_url":"https://codeload.github.com/SultanAyubi360/DiscreteScrollView_Library/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246399803,"owners_count":20770909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-library","android-studio","carousel","carousel-slider","discrete-scroll","item-picker","layoutmanager","page-transformations","swipe","view","viewpager","viewpager2"],"created_at":"2024-12-12T19:10:38.720Z","updated_at":"2026-04-29T00:03:07.030Z","avatar_url":"https://github.com/SultanAyubi360.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DiscreteScrollView\nThe library is a RecyclerView-based implementation of a scrollable list, where current item is centered and can be changed using swipes.\nIt is similar to a ViewPager, but you can quickly and painlessly create layout, where views adjacent to the currently selected view are partially or fully visible on the screen. \n\nA scrollable list of items that centers the current element and provides easy-to-use APIs for cool item animations.\n\n\u003cdiv align=\"center\"\u003e\n\t\n[![](https://jitpack.io/v/SultanAyubi360/DiscreteScrollView_Library.svg)](https://jitpack.io/#SultanAyubi360/DiscreteScrollView_Library/1.0)\n![Status](https://img.shields.io/badge/Status-Active-brightgreen) ![Kotlin](https://img.shields.io/badge/Kotlin-100%25-brightgreen)\n\n\u003c/div\u003e\n\n\n## ✨ Sample Videos\n\n\u003ckbd\u003e\n\n\u003cvideo src=\"https://github.com/user-attachments/assets/5f5e2343-38b5-453e-85aa-f7843b2982ba\" width=\"10\" height=\"30\" /\u003e \n\n\u003c/kbd\u003e\n\n\u003ckbd\u003e\n\n\u003cvideo src=\"https://github.com/user-attachments/assets/cf23d16b-7f59-4db6-8d14-10d36f46b26c\" width=\"10\" height=\"30\" /\u003e\n\n\u003c/kbd\u003e\n\n\u003ckbd\u003e\n\n\u003cvideo src=\"https://github.com/user-attachments/assets/2c5c8617-8130-4f0f-824b-86d376c88fc2\" width=\"10\" height=\"30\" /\u003e\n\n\u003c/kbd\u003e\n\n## Usage\n\n### Step 1\n\n#### In older Gradle Style (Build.gradle (project level))\n```\nallprojects {\n  repositories {\n    ...\n    maven { url \"https://maven.google.com\" }\n    maven { url \"https://jitpack.io\" }\n    maven { url \"https://repo.grails.org/grails/core/\" }\n  }\n}\n```\n\n#### In New Project Structure (Settings.gradle)\n```\ndependencyResolutionManagement {\n    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)\n    repositories {\n        ......\n        maven { url \"https://maven.google.com\" }\n        maven { url \"https://jitpack.io\" }\n        maven { url \"https://repo.grails.org/grails/core/\" }\n        .....\n    }\n}\n```\n\n### Step 2\n\nAdd the dependency in your build.gradle.\n\n# For groovy DSL\n\n```\ndependencies {\n   implementation 'com.github.SultanAyubi360:DiscreteScrollView_Library:1.0'\n}\n```\n\n# For Kotlin DSL\n\n\n```\ndependencies {\n    implementation (\"com.github.SultanAyubi360:DiscreteScrollView_Library:1.0\")\n}\n```\n\n---\n\n## Using DiscreteScrollView Library\n\nThe GitHub project source includes a sample application, that is used for demonstrating the various features currently supported by this library. Once the library is added to your project, you can\ninclude the DiscreteScrollView into your activity/fragment layout using the following code snippets.\n\nThe library uses a custom LayoutManager to adjust items' positions on the screen and handle scroll, however it is not exposed to the client \ncode. All public API is accessible through DiscreteScrollView class, which is a simple descendant of RecyclerView.\n\nIf you have ever used RecyclerView - you already know how to use this library. One thing to note - you should NOT set LayoutManager.\n\n### Initialize in Application Class and mention app class in manifest.\n\n```\n\n@Override\n    public void onCreate() {\n        super.onCreate();\n        instance = this;\n        DiscreteScrollViewOptions.init(this);\u003c!-- initialize here to use in project --\u003e\n    }\n\n\u003capplication\n         android:name=\".App\" \u003c!-- in manifest inside application tag --\u003e\n\u003c/application\n\n```\n\n### Step 3\n\nAdd DiscreteScrollView to your layout either using xml or code:Add the following xml to your layout file.You can use the DiscreteScrollView in following manner:\n\n#### In XML:\n\n```\n \u003ccom.sultanayubi.discretescrollviewlibrary.DiscreteScrollView\n        android:id=\"@+id/item_picker\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\n        android:background=\"@color/galleryBg\"\n        app:dsv_orientation=\"vertical\" /\u003e \u003c!-- orientation is optional, default is horizontal --\u003e\n\n```\n---\n\n### Step 4\n\nReference the View in Kotlin code.\n\n```\nDiscreteScrollView itemPicker = findViewById(R.id.item_picker); \u003c!-- Using Find View By Id --\u003e\nDiscreteScrollView itemPicker = binding.itemPicker; \u003c!-- Using View Binding --\u003e\n\n\nGallery gallery = Gallery.get(); \u003c!-- Using Gallery class have this method --\u003e\nList\u003cImage\u003e data = gallery.getData(); \u003c!-- getData method inside Gallery class --\u003e\n\nitemPicker.setAdapter(new GalleryAdapter(data)); \u003c!-- giving list to our adapter --\u003e\n\n```\n\n#### General\n```\nscrollView.setOrientation(DSVOrientation o); //Sets an orientation of the view\nscrollView.setOffscreenItems(count); //Reserve extra space equal to (childSize * count) on each side of the view\nscrollView.setOverScrollEnabled(enabled); //Can also be set using android:overScrollMode xml attribute\n```\n#### Related to the current item:\n```\nscrollView.getCurrentItem(); //returns adapter position of the currently selected item or -1 if adapter is empty.\nscrollView.scrollToPosition(int position); //position becomes selected\nscrollView.smoothScrollToPosition(int position); //position becomes selected with animated scroll\nscrollView.setItemTransitionTimeMillis(int millis); //determines how much time it takes to change the item on fling, settle or smoothScroll\n\n```\n\n#### Transformations\nOne useful feature of ViewPager is page transformations. It allows you, for example, to create carousel effect. DiscreteScrollView also supports \npage transformations.\n\n```\nscrollView.setItemTransformer(transformer);\nBecause scale transformation is the most common, I included a helper class - ScaleTransformer, here is how to use it:\n\n itemPicker.setItemTransformer(new ScaleTransformer.Builder()\n  .setMaxScale(1.05f) \n  .setMinScale(0.8f) \n  .setPivotX(Pivot.X.CENTER) // CENTER is a default one\n  .setPivotY(Pivot.Y.BOTTOM) // CENTER is a default one\n  .build());\n\n```\n#### Slide through multiple items\n\nTo allow slide through multiple items call:\n```\nscrollView.setSlideOnFling(true);\n\n```\nLower the threshold, more fluid the animation. You can adjust the threshold by calling:\n```\n\nscrollView.setSlideOnFlingThreshold(value);\n\n```\n#### Infinite scroll\n  \nInfinite scroll is implemented on the adapter level:\n```\n\nInfiniteScrollAdapter wrapper = InfiniteScrollAdapter.wrap(yourAdapter);\nscrollView.setAdapter(wrapper);\n```\nAn instance of `InfiniteScrollAdapter` has the following useful methods:\n```\nint getRealItemCount();\n\nint getRealCurrentPosition();\n\nint getRealPosition(int position);\n\n/*\n * You will probably want this method in the following use case:\n * int targetAdapterPosition = wrapper.getClosestPosition(targetPosition);\n * scrollView.smoothScrollTo(targetAdapterPosition);\n * To scroll the data set for the least required amount to reach targetPosition.\n */\nint getClosestPosition(int position);\n\n```\nCurrently `InfiniteScrollAdapter` handles data set changes inefficiently, so your contributions are welcome. \n\n#### Disabling scroll\nIt's possible to forbid user scroll in any or specific direction using:\n\n```\nscrollView.setScrollConfig(config);\n\n```\n\nWhere `config` is an instance of `DSVScrollConfig` enum. The default value enables scroll in any direction.\n\n#### Callbacks\n\n* Scroll state changes:\n```\nscrollView.addScrollStateChangeListener(listener);\nscrollView.removeScrollStateChangeListener(listener);\n\n```\n\n* Scroll:\n```\nscrollView.addScrollListener(listener);\nscrollView.removeScrollListener(listener);\n\npublic interface ScrollListener\u003cT extends ViewHolder\u003e {\n  //The same as ScrollStateChangeListener, but for the cases when you are interested only in onScroll()\n  void onScroll(float scrollPosition, int currentIndex, int newIndex, @Nullable T currentHolder, @Nullable T newCurrentHolder);\n}\n\n```\n* Current selection changes:\n```\n\nscrollView.addOnItemChangedListener(listener);\nscrollView.removeOnItemChangedListener(listener);\n\n```\n\n---\n\n## Reporting an issue\n\nIf you are going to report an issue, I will greatly appreciate you including some code which I can run to see the issue. By doing so you maximize the chance that I will fix the problem. \nBy the way, before reporting a problem, try replacing DiscreteScrollView with a RecyclerView. If the problem is still present, it's likely somewhere in your code.\n\n\n## Find this library useful? :heart:\n\nHowever, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it. :coffee: :hamburger: :fries: :apple:\n\nSupport it by joining stargazers to this. ⭐\n\nAlso, [follow me on GitHub](https://github.com/SultanAyubi360) for my next creations! 🤩\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsultanayubi360%2Fdiscretescrollview_library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsultanayubi360%2Fdiscretescrollview_library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsultanayubi360%2Fdiscretescrollview_library/lists"}