Home > Android > How to implement a paging feature in Android

How to implement a paging feature in Android

One day I needed to create a paging feature in Android. Something to create a swipe action in Android, like the home screen. After searching in Google, I discovered that was possible to make this effects using a HorizontalScrollView. It’s a good idea. So, I adapted some codes according my necessity. I created a class (PaginationLayout). You just need to add elements into this layout and it will do all work.

Basically the PaginationLayout class creates two views: a bar with “Previous” and “Next” buttons and a horizontal scroll, one below the other. The paging effect is built using the scroll. Gestures are calculated to move and stop just to pass an exact page (visible screen size). It also applies to the click event of the buttons.

The complete code the project is exposed in the Github: here or direct download zip file here

A video was added on Youtube to quickly show the feature:

Usage example:

public class Sample extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        // creates the Pagination Layout
        PaginationLayout paginationLayout = new PaginationLayout(this);
        paginationLayout.setLayoutParams(new LayoutParams(
			  LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        // creates content only for sample
        TableLayout table = new TableLayout(this);
        TableRow row = new TableRow(this);
        TableRow row2 = new TableRow(this);
        .... and blablabla ...

        for(int i = 0; i< 50;i++){
            Button button = new Button(this);
            button.setText("Button " + i);
            if (i%2==0) {
            } else {
        // add the content in pagination
        // set pagination layout

  1. Kimae
    10 de May de 2011 at 05:41

    Can I please get the whole project? Thank you very much.

    • 10 de May de 2011 at 10:49

      Sure! The whole project is public! If you use it and share any suggestion, I would really appreciate.

  2. kalai
    28 de September de 2011 at 03:38

    Hai paul,
    ur tutorial is very much useful for me………………………………….

  3. 5 de February de 2014 at 14:54

    If you are not sure of the software that you need in getting your phone or tablet rooted, you
    can make use of a forum for android where you would have your needs met.
    However, the app itself takes up more space than necessary and will continue adding to
    the problem. You must seek aid by an skilled technician to
    assist remove that kind of virus.

  1. 6 de August de 2012 at 03:21

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: