Reader small image

You're reading from  Android 9 Development Cookbook - Third Edition

Product typeBook
Published inOct 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781788991216
Edition3rd Edition
Languages
Tools
Right arrow
Author (1)
Rick Boyer
Rick Boyer
author image
Rick Boyer

Rick Boyer has been programming professionally for over 20 years. He has written apps on Windows, created websites, and coded for various mobile devices, including Windows CE, Windows Phone, and Android. Almost eight years ago, he took the plunge and started his own software consulting business, NightSky Development, focusing exclusively on Android development.
Read more about Rick Boyer

Right arrow

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:

  1. Copy four images to the /res/drawable folder and name them slide_0 through slide_3, keeping the original file extensions.
  2. Create a new layout file called fragment_slide.xml using 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...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Android 9 Development Cookbook - Third Edition
Published in: Oct 2018Publisher: PacktISBN-13: 9781788991216

Author (1)

author image
Rick Boyer

Rick Boyer has been programming professionally for over 20 years. He has written apps on Windows, created websites, and coded for various mobile devices, including Windows CE, Windows Phone, and Android. Almost eight years ago, he took the plunge and started his own software consulting business, NightSky Development, focusing exclusively on Android development.
Read more about Rick Boyer