Swipe half page in ViewPager (from compatibility pack)

I am using ViewPager with PageAdapter (from v4 compatibility pack) to scroll among the horizontal list of boxes. The problem is that my second box from the first page is the first field on the second page (visually and conceptually). Something like that:

enter image description here

The way I do it now works. However, this becomes strange, because in the middle of the scroll a situation appears when the same block appears twice (as shown in the image).

Is there a way to scroll only half the page?

EDIT:

Boxes are an abstraction. In fact, each box is a ListView , and I create different pages simply by changing the adapter of each ListView .

+6
source share
2 answers
  • Create one snippet per page
  • Override getPageWidth () in PageAdapter to display more than one page

the code:

 @Override public float getPageWidth(int position) { float nbPages = 2; // You could display partial pages using a float value return (1 / nbPages); } 
+26
source

Yes, use the width of the child as half the page. Therefore, the scroll that causes the next child will skip half the page. Good luck

Edit: checked your sketch again, try doing 1, 2, 3 ... as different child elements. (I predict most of the solution, assuming it will react like GalleryView)

+2
source

Source: https://habr.com/ru/post/903574/


All Articles