The MultiViewPager is an extension of the support-v4 library's ViewPager that allows the pages to be wider or narrower than the ViewPager itself. It takes care of aligning the pages next to each other, and always keeping the selected page centered.

Overview

MultiViewPager

Android Arsenal Build Status

UPDATE: This behavior is now included in the RecyclerView for support lib 24.2.0 and later. Please look at using LinearSnapHelper.

The MultiViewPager is an extension of the support-v4 library's ViewPager that allows the pages to be wider or narrower than the ViewPager itself. It takes care of aligning the pages next to each other, and always keeping the selected page centered.

Sample app

Sample

Simply add the MultiViewPager into your layout:

<com.pixplicity.multiviewpager.MultiViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:matchChildWidth="@+id/child_view_to_match" />

Be sure to declare the app namespace:
xmlns:app="http://schemas.android.com/apk/res-auto"

Take note of the custom attribute matchChildWidth. This attribute should match an ID in the ViewPager's first child view. In the sample project, the layout of the pages is:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${relativePackage}.${activityClass}" >

    <FrameLayout
        android:id="@+id/vg_cover"
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:layout_centerInParent="true" >

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="16dp"
            android:background="@drawable/bg_page"
            android:scaleType="centerInside"
            android:src="@drawable/im_pixplicity"
            tools:ignore="ContentDescription" />
            
    </FrameLayout>

</RelativeLayout>

The child view with ID @id/vg_cover will determine the width of the page. In this example, the width would be 200dp. In order to get this hooked up, we provide MultiViewPager with the reference to the child, @id/vg_cover:

<com.pixplicity.multiviewpager.MultiViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:matchChildWidth="@+id/vg_cover" />

In this way, it knows to size the pages according to the dimension of that View or ViewGroup.

Download

Download the latest AAR or grab via Maven:

<dependency>
  <groupId>com.pixplicity.multiviewpager</groupId>
  <artifactId>library</artifactId>
  <version>1.0</version>
  <type>aar</type>
</dependency>

or Gradle:

compile 'com.pixplicity.multiviewpager:library:1.0'

License

Licensed under the Apache license.

Comments
  • Unsusual behaviour with if number of elements more than 5?

    Unsusual behaviour with if number of elements more than 5?

    If number of elements in the list greater than 5 then Fragment view pager has the wired behavior as last element of the list gets hide on scrolling till end.

    Maybe some hard coded values.

    invalid 
    opened by umesh7715 9
  • Fragments not visible on Scrolling to the END

    Fragments not visible on Scrolling to the END

    i have this viewpager implemented , but if the viewpager has large number of items , and if we scroll to one end and move back then the middle items of the viewpager are getting invisible .

    opened by peter1408 4
  • Left-alignment of pages

    Left-alignment of pages

    Thanks a million for this awesome library.

    I need to make some changes in this library to achieve the following effect:

    1. When there is only one item on pager, the item must be centered:
      screen shot 2015-02-12 at 3 31 23 pm
    2. When there are more than one item, the initial screen should be like this:
      screen shot 2015-02-12 at 3 37 40 pm
    3. When the user scrolls the pages( items greater than 1), each selected page now will be centered like this:
      screen shot 2015-02-14 at 4 20 52 pm

    I have achieved such effect by using two kind of layout on PagerAdapter

    1. View with layoutCenterInParent

    2. Other View having same content as 1 but no layoutCenterInParent

      On PagerAdapter, I have made following changes

    //Use this layout to inflate on instantiateItem
    private int getLayoutId(int position) {
      int layoutId = getCount() > 1 ? R.layout.item_video :  
                             R.layout.item_video_center;
      return layoutId;
    }
    //call this method when page changes from 0 to 1 and vice versa
    public boolean changeToCenter(int position) {
      if (getCount() > 1) {
        if (position == 0 && layoutId == R.layout.item_video_center) {
            layoutId = R.layout.item_video;
            notifyDataSetChanged();
            return true;
        } else if (layoutId == R.layout.item_video) {
            layoutId = R.layout.item_video_center;
            notifyDataSetChanged();
            return true;
        }
      }
      return false;
    }
    

    And on onPageChangeListener on MultiViewPager, I have made following changes

    @Override
    public void onPageSelected(int i) {
      boolean smoothScroll = ((VideoItemPagerAdapter) adapter).changeToCenter(i);
      if (smoothScroll)
        scrollToPosition(i);
    }
    
    private void scrollToPosition(final int i) {
      new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
          pager.setCurrentItem(i, true);
        }
      }, 0);
    }
    

    This logic gives me my desired effect but on page change from 0 to 1 and vice versa the ViewPager stutters, due to layout changes. Further, this process is resource intensive during page change from 0 to 1 and vice versa. So any smart way I can do this. Your logic or hint would be more than enough.

    enhancement 
    opened by laaptu 4
  • Item carousel with percentage width

    Item carousel with percentage width

    Hi, First of all, thank you for your hard work :). The thing is, I'm currently trying to create a carousel thanks to a ViewPager. I succeed to make a multiviewpager but by using a tricky solution :

    root.post(new Runnable() {
                @Override
                public void run() {
                    CarouselViewPager carousel = (CarouselViewPager) getActivity().findViewById(R.id.carousel);
                    int width = root.getWidth();
                    int paddingWidth = (int) (width * 0.22);
                    root.setPadding(paddingWidth, 0, paddingWidth, 0);
                    root.getLayoutParams().width = width-(paddingWidth*2);
                    root.requestLayout();
    
                    carousel.setPageMargin(-(paddingWidth-8)*2);
                }
            });
    

    I saw in your sample that you set a fixed width (200dp), is it possible with your solution, to have a child item with ie : 50% of the width of the ViewPager ? Regards.

    question 
    opened by 1ud0v1c 2
  • How do I set click listeners on pages?

    How do I set click listeners on pages?

    I have a MultiViewPager in my current app, I have total of 8 items and I am displaying around 5 items at a time. What I am trying to do is to make the item selected when I click on it. How can I do that ? I tried setting click listener on the Fragment's view itself passing position to it's constructor, but that is giving me erratic results. I also tried getting hold of all the view's for all the fragments and setting click listener on those, but that is giving me counts up to 5 only.

    Please Help, This is an important feature for my app.

    help wanted question 
    opened by ishan1608 2
  • Content of view is streached

    Content of view is streached

    I am using this library to showing cards with images and some other content. but the problem is that when I set card's width and height to desired, the content of the card is stretched. Please tell me the solution.

    help wanted 
    opened by raj4vedi 1
  • multiview pager error

    multiview pager error

    Process: com.example.abc.fragmentsapplication, PID: 8443 java.lang.NullPointerException: MatchWithChildResId did not find that ID in the first fragment of the ViewPager; is that view defined in the child view's layout? Note that MultiViewPager only measures the child for index 0.

    opened by engr-erum 1
  • How do I feeding page change events into the selected fragment?

    How do I feeding page change events into the selected fragment?

    I am trying to make all the icons white except the currently selected one which will be blue. I am trying to do this using onPageChangeListener. I have added 8 Fragments and my PagerAdapter reflects the same but when I am accessing the childCount of MultiViewPager itself, it only shows 6 and crashes when I swipe my way to the right end of MultiViewPager

    I tried getting hold of the fragments and their views using an array in the activity. However it is not giving me irratic behaviour. Some views get regenerated out of nowhere. I can't seem to wrap my head around it. Please Help

    help wanted question 
    opened by ishan1608 1
  •  The first and the last item scroll to center question?

    The first and the last item scroll to center question?

    I need to remove the padding from each items.. And if the index of the item is 0,I need to make it to screen's leff ! I don't wanna let the first view scroll to center in screen.. Just like this: qq 20150722140758

    20150722134625

    In a simple word,I don't want the first and the last item scroll in center..

    .Tell me how to do it...Thankls a lot..

    duplicate 
    opened by MIkeeJY 1
  • Enhance this feature to be more facebook like interaction.

    Enhance this feature to be more facebook like interaction.

    I have been thinking deep into library and I am trying to make it possible to animate like facebook.

    When I tap in the middle picture it will able to zoom into fullscreen. As fullscreen, it takes the width of current selected image in the center and release the bounce to the screen width and the background turns dark. Is that possible achieve this effect?

    enhancement wontfix 
    opened by jjhesk 1
  • Cannot compile the project

    Cannot compile the project

    If you clone and open the project with Android Studio 3 you get this error message:

    Error:Unsupported method: BaseConfig.getApplicationIdSuffix(). The version of Gradle you connect to does not support that method. To resolve the problem you can change/upgrade the target version of Gradle you connect to. Alternatively, you can ignore this exception and read other information from the model.

    I tried modifying classpath 'com.android.tools.build:gradle:1.1.3' to classpath 'com.android.tools.build:gradle:3.0.0' but I get another error (Error:The "android" command is no longer included in the SDK. Any references to it (e.g. by third-party plugins) should be removed.)

    opened by nordfalk 0
Owner
Pixplicity
Pixplicity
UltraViewPager is an extension for ViewPager to provide multiple features in a single ViewPager.

UltraViewPager 中文文档 ProjectUltraViewPager is a ViewPager extension that encapsulates multiple features, mainly to provide a unified solution for multi

Alibaba 5k Dec 20, 2022
Android auto scroll viewpager or viewpager in viewpager

Android Auto Scroll ViewPager ViewPager which can auto scrolling, cycling, decelerating. ViewPager which can be slided normal in parent ViewPager. Att

Trinea 1.7k Dec 10, 2022
Combine ViewPager and Animations to provide a simple way to create applications' guide pages.

WoWoViewPager WoWoViewPager combines ViewPager and Animations to provide a simple way to create applications' guide pages. When users are dragging WoW

黄伟平 2.7k Dec 30, 2022
An interactive indicator to navigate between the different pages of a ViewPager

Android PagerSlidingTabStrip (default Material Design) This library is not maintained anymore and there will be no further releases. For most of the c

JPARDOGO 2.2k Jan 4, 2023
Don't write a ViewPager Adapter! Hook up your ViewPager to your data model using Android Data Binding Framework. With Kotlin support!

Don't write a ViewPager Adapter! Hook up your ViewPager to your data model using Android Data Binding Framework. Show some ❤️ ?? Sweet and short libra

Rakshak R.Hegde 180 Nov 18, 2022
An android ViewPager extension allowing infinite scrolling

NO LONGER MAINTAINED LoopingViewPager An android ViewPager extension allowing infinite scrolling. You can use it with "standart" PagerAdapter (inflati

Leszek Mzyk 992 Nov 10, 2022
Persons cards list viewpager - Persons cards list viewpager using kotlin

persons_cards_list_viewpager Дизайн и условие взяты из https://github.com/appKOD

Mironov Ury 1 Mar 1, 2022
Paging indicator widgets compatible with the ViewPager from the Android Support Library and ActionBarSherlock.

Android ViewPagerIndicator Paging indicator widgets that are compatible with the ViewPager from the Android Support Library to improve discoverability

Jake Wharton 10.2k Jan 3, 2023
Paging indicator widgets compatible with the ViewPager from the Android Support Library and ActionBarSherlock.

Android ViewPagerIndicator Paging indicator widgets that are compatible with the ViewPager from the Android Support Library to improve discoverability

Jake Wharton 10.2k Jan 5, 2023
PagedGrid - Custom android view composed by multiple page grids with custom content and layout

PagedGrid A PagedGrid is a ViewPager which pages are GridLayout with equal distributed rows and columns. This project is an Android library, written i

Matteo Pellegrino 1 Jan 23, 2019
This project aims to provide a working page flip implementation for usage in ListView.

Changes: Made clickable views like a button clickable inside the FlipViewPager. Use RecyclerView. Updated to API 23. Added support for close clicks on

Yalantis 1.8k Dec 13, 2022
A Page Indicator Lib is realized in a different way.

#FlycoPageIndicator A Page Indicator Lib is realized in a different way. Support for Android 2.2 and up. ##Demo ####Here is a DemoApk download ##Gradl

Flyco 537 Dec 17, 2022
[Development stopped in 2014. Unfinished and not stable - not recommended to use.] An easy-to-use ViewPager subclass with parallax background effect for Android apps.

Development stopped in 2014 Not developed since 2014. Unfinished and not stable - not recommended to use. ParallaxViewPager An easy-to-use ViewPager s

Andras Kindler 437 Dec 29, 2022
Library containing common animations needed for transforming ViewPager scrolling for Android v13+.

ViewPagerTransforms Library containing common animations needed for transforming ViewPager scrolling on Android v13+. This library is a rewrite of the

Ian Thomas 2.5k Dec 31, 2022
A custom ViewPager title strip which gives continuous feedback to the user when scrolling

SmartTabLayout A custom ViewPager title strip which gives continuous feedback to the user when scrolling. This library has been added some features an

ogaclejapan 7k Jan 1, 2023
A Material Design ViewPager easy to use library

MaterialViewPager Material Design ViewPager easy to use library Sample And have a look on a sample Youtube Video : Youtube Link Download In your modul

Florent CHAMPIGNY 8.2k Dec 29, 2022
A different beautiful ViewPager, with quick swipe controls

HollyViewPager Usage Add a HollyViewPager in your layout <com.github.florent37.hollyviewpager.HollyViewPager android:id="@+id/hollyViewPager"

Florent CHAMPIGNY 1.1k Dec 9, 2022
Augment Android's ViewPager with wrap-around functionality.

Infinite View Pager Augment Android's ViewPager with wrap-around functionality. Original StackOverflow question: http://stackoverflow.com/questions/75

Antony Tran 692 Dec 14, 2022
ViewPager that slides vertically.

ExpandablePager Layout that contains a ViewPager and can slide vertically between 2 states (expanded and collapsed). #Requirements Android 4.0+ (Ice C

Telenav Inc 716 Sep 15, 2022