Creating a slideshow with ViewPager
This recipe will show you how to create a slideshow using the ViewPager class. Here is a screenshot showing a transition from one picture to another:

Getting ready
Create a new project in Android Studio and call it SlideShow. Use the default Phone & Tablet options and select Empty Activity when prompted for the Activity Type.
We need four images for the slideshow.
How to do it...
We'll create a Fragment to display each image for our slideshow, then set up ViewPager in the Main Activity. Here are the steps:
- Copy four images to the
/res/drawablefolder and name themslide_0throughslide_3, keeping the original file extensions. - Create a new layout file called
fragment_slide.xmlusing the following XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget...