Android Image Slider Using ViewPager
You have seen many Android apps with sliding images with circle page indicator at top. Today we are going to learn the same thing for our app.
Before proceeding we need a superb library called ViewPagerIndicator-Library that we can get from Github created by JakeWhartom. Just download it and import the library into your project.
We are going to use ViewPager for Sliding the images so if anyone of you are unaware of viewpager can go and check my tutorial about ViewPager.
Features of this app:
Video Demo
Let’s start with the Example:
1. Create a new project in Android Studio by navigating to File ⇒ New Android ⇒ Application Project and fill required details. By default my activity is MainActivity.java.
2. First create an xml layout file naming activity_main.xml that contains viewpager and CirclePageIndicator that is provided by JakeWhartom library.
3. Now create a new xml layout naming slidingimages_layout.xml that contains an ImageView. It is custom view for our images placing.
4. For custom view we have to create a java file for connecting the custom view with the user interface. I named the class SlidingImage_Adapter.java extending PagerAdapter since we are dealing with ViewPager. This class just fetch the Images from Array and display over imageView and rest will be handled by viewpager.
5. Finally come to your MainActivity.java and add the following code. In this class at start we set the Timer that changes the images at particular interval of time and also when user swipes the viewpager will change the next image.
6. Now, you are all done, run your app and you will get the output as shown in video.
ADD in build gradle
ADD in build gradle
//slider compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
Thanks.
0 comments:
Post a Comment