ViewPager - get a partial view of the next page

I am trying to achieve this in ViewPager

The first fragment (blue) is displayed, and the beginning of the next fragment should also be displayed, so the user understands what he can use to switch views. The idea is to scroll 20% of the screen programmatically to the left.

Any thoughts are welcome.

EDIT: This is exactly what I need: the central view should overlap both side views

enter image description here

+45
android android-viewpager
Mar 28 2018-12-12T00:
source share
4 answers

You can try adding this to your PageAdapter:

public float getPageWidth(int position) { if (position == 0 || position == 2) { return 0.8f; } return 1f; } 
+44
Aug 28 '12 at 10:12
source share

Try using a negative value for ViewPager.setPageMargin .

+15
Mar 29 '12 at 2:32
source share

This function worked better than the answer marked as correct (for me anyway).

 @Override public float getPageWidth(int position) { return 0.9f; } 

Just put it in your own PagerAdapter class.

+12
Jun 05 '14 at 21:50
source share
 viewpager.setClipToPadding(false); viewpager.setPageMargin(-50); 
+3
Mar 04 '16 at 8:33
source share



All Articles