SliderView library

Additional

Language
Java
Version
1.0 (Mar 28, 2019)
Created
Mar 21, 2019
Updated
Mar 30, 2019
Owner
Nikhil Sachdeva (nikhil-sachdeva)
Contributor
Nikhil Sachdeva (nikhil-sachdeva)
1
Activity
Badge
Generate
Download
Source code
APK file

Show card

SliderViewLibrary

An easy to use Android Library to get slides in apps using images or image URLs

Medium Article to implement SliderView from scratch. Link

Also here

Gradle

Step 1. Add this in your root build.gradle at the end of repositories:

 allprojects {
  repositories {
   ...
   maven { url 'https://jitpack.io' }
  }
 }

Step 2. Add the dependency

 dependencies {
         implementation 'com.github.nikhil-sachdeva:SliderViewLibrary:1.0'
 }

Add SliderView to your activity_main.xml.

<com.example.sliderviewlibrary.SliderView
    android:id="@+id/sliderView"
    android:layout_centerHorizontal="true"
    android:layout_width="300dp"
    android:layout_height="200dp"/>

Adjust layout height and width based on the size of images to be used.

Either use list of images as resources.

ArrayList<Integer> images = new ArrayList<>();
images.add(R.drawable.pic1);
images.add(R.drawable.pic2);
images.add(R.drawable.pic3);
sliderView.setImages(images);

Or use list of URLs. (Add < uses-permission android:name="android.permission.INTERNET"/ > in AndroidManifest.xml to access internet.)

ArrayList<String> Urls = new ArrayList<>();
Urls.add("url1");
Urls.add("url2");
Urls.add("url3");
sliderView.setUrls(Urls);

To implement time-based auto swiping, define DELAY_MS and PERIOD_MS as int variables to define delay and time period for swipes respectively. And then execute a TimerTask on main UI thread as follows.

TimerTask task = sliderView.getTimerTask();
Timer timer = new Timer();
timer.schedule(task,DELAY_MS,PERIOD_MS);

And Voila!