• This repository has been archived on 07/Jan/2023
  • Stars
    star
    233
  • Rank 166,627 (Top 4 %)
  • Language
    Java
  • License
    MIT License
  • Created over 4 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An android carousel library for RecyclerView

CarouselView

License: MIT

An android carousel library for RecyclerView

Examples

Demos

Full Image Item Centered Item Start
alt text alt text

Installation

Current Version:

Gradle

Add the following

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
dependencies {
    implementation 'com.github.jama5262:CarouselView:1.2.2'
}

Great the project has been setup 👍

Usage

XML

Below is all the XML attributes that the CarouselView has

<com.jama.carouselview.CarouselView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:enableSnapping="true"
    app:scaleOnScroll="false"
    app:setAutoPlay="true"
    app:setAutoPlayDelay="3000"
    app:carouselOffset="center"
    app:indicatorAnimationType="drop"
    app:indicatorRadius="5"
    app:indicatorPadding="5"
    app:indicatorSelectedColor="@color/colorAccent"
    app:indicatorUnselectedColor="@color/colorPrimary"
    app:size="10"
    app:spacing="10"
    app:resource="@layout/image_carousel_item"/>

Kotlin Implementation

class CarouselActivity : AppCompatActivity() {

    private val images = arrayListOf(R.drawable.boardwalk_by_the_ocean, 
            R.drawable.journal_and_coffee_at_table, R.drawable.tying_down_tent_fly)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_carousel)

        val carouselView = findViewById<CarouselView>(R.id.carouselView)

        carouselView.apply {
            size = images.size
            resource = R.layout.carousel_item
            autoPlay = true
            indicatorAnimationType = IndicatorAnimationType.THIN_WORM
            carouselOffset = OffsetType.CENTER
            setCarouselViewListener { view, position ->
                // Example here is setting up a full image carousel
                val imageView = view.findViewById<ImageView>(R.id.imageView)
                imageView.setImageDrawable(resources.getDrawable(images[position]))
            }
            // After you finish setting up, show the CarouselView
            show()
        }
    }
}

Java Implementation

class CenteredCarouselActivity extends AppCompatActivity {

  private int[] images = {R.drawable.boardwalk_by_the_ocean,
      R.drawable.journal_and_coffee_at_table, R.drawable.tying_down_tent_fly};

  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_centered_carousel);
    
    CarouselView carouselView = findViewById(R.id.carouselView);
    
    carouselView.setSize(images.length);
    carouselView.setResource(R.layout.center_carousel_item);
    carouselView.setAutoPlay(true);
    carouselView.setIndicatorAnimationType(IndicatorAnimationType.THIN_WORM);
    carouselView.setCarouselOffset(OffsetType.CENTER);
    carouselView.setCarouselViewListener(new CarouselViewListener() {
      @Override
      public void onBindView(View view, int position) {
        // Example here is setting up a full image carousel
        ImageView imageView = view.findViewById(R.id.imageView);
        imageView.setImageDrawable(getResources().getDrawable(images[position]));
      }
    });
    // After you finish setting up, show the CarouselView
    carouselView.show();
  }
}

Below are all the methods available

Name Description Values Default Is XML Attribute
show Show the carousel No
enableSnapping Enables and disables snapping true, false true Yes
hideIndicator Show and hide indicator true, false false No
setAutoPlay Enable auto play true, false false Yes
setAutoPlayDelay Set delay time for auto play Takes in integers 2500 (2.5 sec) Yes
setCarouselOffset Sets the carousel item to display center or from start OffsetType.CENTER, OffsetType.START OffsetType.START Yes
setCurrentItem This sets the item position Takes item position No
setIndicatorAnimationType Sets the indicator animation type. This is thanks to romandanylyk AnimationType.DROP, FILL, NONE, SWAP, WORM, COLOR, SCALE, SLIDE, THIN_WORM, SCALE_DOWN AnimationType.NONE Yes
setIndicatorRadius Sets the radius of the indicator Takes in radius integer Yes
setIndicatorPadding Sets the padding of the indicator Takes in padding integer Yes
setIndicatorSelectedColor Sets the color of the selected indicator Takes in color type Set to black Yes
setIndicatorUnselectedColor Sets the color of the unselected indicator Takes in color type Set to grey Yes
setScaleOnScroll Sets the carousel item to scale on scroll true, false false Yes
setSize Sets the number of items to display in the carousel Takes in size integer Yes
setSpacing Sets the spacing between items Takes in spacing integer 0 Yes
setResource Sets the item to be displayed in the carousel Takes in a layout item Yes
setCarouselViewListener Adding custom view No
setCarouselScrollListener Listens for scrolls No

Support

Reach out to me at one of the following places!

License

MIT License

Copyright (c) 2019 Jama Mohamed

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

More Repositories

1

jiffy

Jiffy is a Flutter (Android, IOS and Web) date time package for parsing, manipulating, querying and formatting dates
Dart
515
star
2

MPESA-Biz-No-Detector

An android detection library that uses Azure Computer Vision Read API to detect MPESA business and/or account numbers from images
Kotlin
33
star
3

tensorflow-emotion-text-detector

This is an app that comprises of dockerized tensorflow serving model and flask-react server that communicate together using docker-compose to predict the emotion of a text
17
star
4

AndroidAnimation

An android library for easy and simple view animations
Kotlin
10
star
5

blood-donation-system-android

This project aims to develop a web-based application for the hospital and a mobile base application for donors that will reduce the time taken to get a specific blood type e.g. A+ from registered donors within a geographical area in case of emergencies and in the process store data in a centralized database that is accessible to all hospitals.
Kotlin
10
star
6

blood-donation-system-web

This project aims to develop a web-based application for the hospital and a mobile base application for donors that will reduce the time taken to get a specific blood type e.g. A+ from registered donors within a geographical area in case of emergencies and in the process store data in a centralized database.
Vue
6
star
7

Receipt-Text-Recognition-App

A simple boring app that detects the total cost of a receipt
Kotlin
2
star
8

dialogflow-reddit-chatbot

A dailogflow chatbot that consumes the reddit api using a flask server-side and react client-side
JavaScript
2
star
9

weather-app

An vuejs weather app that consumes the open weather api
JavaScript
1
star
10

react-link-previewer

This is a react app that displays a visual preview and brief description of the link or links passed
JavaScript
1
star