GithubHelp home page GithubHelp logo

tesladam / carouselview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jama5262/carouselview

0.0 1.0 0.0 6.74 MB

An android carousel library for RecyclerView

Home Page: https://jitpack.io/#jama5262/CarouselView

License: MIT License

Java 82.90% Kotlin 17.10%

carouselview's Introduction

CarouselView

License: MIT

An android carousel library for RecyclerView

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

Maven

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
<dependency>
    <groupId>com.github.jama5262</groupId>
	<artifactId>CarouselView</artifactId>
    <version>1.1.0</version>
</dependency>

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.

carouselview's People

Contributors

jama5262 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.