0

I setup my ViewPager to only show preview of 1 page on the right side using setPadding and pageMargin:

viewpager.setPadding(smallSpace, smallSpace, largeRightPadding, smallSpace)
viewpager.pageMargin = normalSpace
viewpager.offscreenPageLimit = 2

largeRightPadding is large enough to show my right preview page. My current UI looks like this:

This is how the first item with right preview looks: ViewPager first item

If I scroll to the last item, there will be empty space on the right ViewPager last item

I want to make it likes this, NO empty space for the last item, instead it will show the preview of the left page ViewPager expected

Thanks in advance

Tam Huynh
  • 2,026
  • 1
  • 16
  • 20
  • 2
    i just have a little question,why you dont use recyclerview instead – shadow Jan 03 '20 at 10:21
  • Hi @shadow , Currently changing the code to `RecyclerView` is quite complex, and I am not sure if it works for this case. I remember 1 time I happen to make the `ViewPager` behave like that but now when I need it I cannot find any solution. Maybe I will try `RecyclerView` if there is `ViewPager` solution – Tam Huynh Jan 03 '20 at 10:25
  • 1
    yes,you should try to set the with of item to 2/3 with of screen ( in onCreateViewHolder) and your recyclerview will work well :D – shadow Jan 03 '20 at 10:28
  • Can you try `viewPager. setClipToPadding(false)` and run? – Kushal Jan 03 '20 at 12:44
  • Hi @Kushal, I've set `clipToPadding='false'` in the xml already, that's why I can see the preview page on the right – Tam Huynh Jan 03 '20 at 14:13

0 Answers0