Home > DeveloperSection > Forums > Set pages pre-view in ViewPager
Glen Martin
Glen Martin

Total Post:27

Points:191
Posted on    November-13-2015 5:40 AM

 Android Android  Android Controls 
Ratings:


 1 Reply(s)
 314  View(s)
Rate this:
You can help me with this? (Make preview of next page on screen) 



Mayank Tripathi
Mayank Tripathi

Total Post:397

Points:3117
Supported
Posted on    November-13-2015 5:51 AM

Well... there is a way to do this. You need to keep 2 or 3 items in memory with:
vpPager.setOffscreenPageLimit(3); // or 2
Then, tune your viewpager like this:
<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:gravity="center"
    android:layout_width="match_parent"
    android:layout_height="0px"
    android:paddingLeft="24dp"
    android:paddingRight="12dp"
    android:layout_weight="1" />
Next, you need to tune these properties of the pager in the containing fragment or activity:

ViewPager vpPager = (ViewPager) view.findViewById(R.id.vpPager);
vpPager.setClipToPadding(false);
vpPager.setPageMargin(12);
// Now setup the adapter as normal
Finally, adjust the width inside the adapter:
class MyPageAdapter : FragmentStatePagerAdapter {
    @Override
    public float getPageWidth (int position) {
        return 0.93f;
    }   
    // ...
}

Don't want to miss updates? Please click the below button!

Follow MindStick