Home > Tutorials > Create application with Swipe gesture to navigate page like Google Play

Create application with Swipe gesture to navigate page like Google Play

Android users might already have been familiar with Google Play application, which first, I think,  inspires the pattern of horizontal swipe gesture to navigate among content pages.

This article is gonna show you how to do a very very quick simple application that does the same pattern.

Swipe Pattern Sample

Swipe Pattern Sample

There will be three pages, each page will display a sample image of that page as swiping along. My sample, I put: “Girl, Dog & Cat”.

A – Requirements

– ViewPagerIndicator library, you can get it from here: http://viewpagerindicator.com/

– Android Support Package Library v4, well, you can either download the above package and use the already-had libs or get it from SDK Update. Either way is fine.

B – Project

Well, since I’m an Ant user, I prefer to do stuffs in command-line, so this tutorial will probably in command-mode.

1. Create the project

$ create project --target 2 --name Droid05 --path ./Droid05 --activity MainScreen --package pete.apps.study.droid05

Now project is ready for the next step.

2. Configure libs

– After downloading the ViewPagerIndicator package, you need to update the library in order to get Ant build.xml for the job. Please refer to my previous post: https://xjaphx.wordpress.com/2012/12/26/build-viewpagerindicator-with-ant/
– Now go to config the library reference, edit the project.properties and add this line


that is my case, you should locate to your correct directory where you put the /library of the ViewPagerIndicator.
– To test the config, you can just type to confirm

$ ant clean debug

If it succeeds, it means fine.
3. Implement the code
– Create the layout, pretty much simple, there will use a TitlePageIndicator and a ViewPager, main.xml

$ vi res/
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

– Create a custom Adapter inherits from PagerAdapter for controlling the ViewPager’s work, ViewPagerAdapter.java

package pete.apps.study.droid05;

import android.content.Context;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

public class ViewPagerAdapter extends PagerAdapter {

    private static String[] titles = new String[] {

    private static int[] images = new int[] {

    private final Context context;

    public ViewPagerAdapter(Context context) {
        this.context = context;

    public String getPageTitle(int position) {
        return titles[position];

    public int getCount() {
        return titles.length;

    public Object instantiateItem(ViewGroup container, int position) {
        ImageView view = new ImageView(this.context);
        ((ViewPager) container).addView(view, 0);
        return view;

    public void destroyItem(ViewGroup container, int position, Object object) {
        ((ViewPager) container).removeView((ImageView) object);

    public boolean isViewFromObject(View view, Object object) {
        return view.equals(object);


– Finally the MainScreen.java

ackage pete.apps.study.droid05;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.Window;
import android.view.WindowManager;
import com.viewpagerindicator.TitlePageIndicator;

public class MainScreen extends Activity
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState)
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);


        ViewPagerAdapter adapter = new ViewPagerAdapter(this);
        ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
        TitlePageIndicator title = (TitlePageIndicator) findViewById(R.id.titles);

4. Execute the final
– Let’s build and run the code to see the results

$ ant clean debug install

C – Get source

– Get full source code at: Browse Source


Well, enjoy and create your amazing application !


Pete Houston


  1. Nitish
    March 8, 2014 at 1:42 am

    Is there a way to achieve the same functionality using HTML5?

  2. james
    December 15, 2013 at 9:43 am

    Even loading the third party dependencies using ant this SwipeGesture code wouldn’t compile for me (way too many errors that wouldn’t clear).

    You might want to consider re-writing it so it doesn’t depend on Jake Wharton’s ViewPagerIndicator, the use of which is awkward, because as JW’s github page says:
    “A standalone JAR is not possible due to the theming capabilities offered by the indicator widgets.”

    Here’s the good news though..
    Even though the Droid05 SwipeGesture code doesn’t work
    the SQLiteStudy code works great:

    ..as does your Application Launcher code (which also uses ListView very effectively):

    You should really consider moving the Application Launcher code to your the github page: (the current repository of the Droid05 and SQLiteStudy code).

    I also found your Image Manipulation / Processing code helpful to study.
    In case anyone couldn’t find them they are towards the bottom of the tutorials list page:

    You should bundle all the different Image Processing code snippets together as a single Image Processing multi-demo app and also host it on your github page!

    Thanks for sharing some great code and I have your tips page bookmarked also:

    • December 17, 2013 at 11:36 am

      thanks james,

      I’m working on it currently.
      I will move all stuffs to my new site: http://pcode.petehouston.com/, however, this site still keeps running with all existed content.

  3. December 30, 2012 at 6:06 pm

    Hello there, I found your site by the use of Google whilst looking for a similar matter, your site came up, it appears good. I have bookmarked to favourites|added to bookmarks.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: