Display Multiple Pages With ViewPager2

Nathan Sokalski 4,111 Reputation points
2022-12-09T19:04:52.523+00:00

I have a ViewPager2 with which I want to display multiple pages (at least while the user is scrolling/swiping). I have never used ViewPager2 before (although I have used RecyclerView). I have created the Layout, ViewHolder & Adapter, so I have a functional ViewPager2 with the appropriate data & each individual page is displayed correctly, it is the UI while selecting a new item that I need to modify. How can I change the number of displayed items? Thanks.

Developer technologies .NET Xamarin
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2022-12-12T03:07:46.527+00:00

    Hello,

    In fact, for this problem, Google has officially made an example of ViewPager2 with 5 pages, please refer to Slide between fragments using ViewPager2.

    Update:

    If you want to display multiple pages at the same time in a ViewPager2, then you can override the GetPageWidth method in your adapter. Please refer to PagerAdapter-getPageWidth

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Graham McKechnie 441 Reputation points
    2022-12-13T02:21:33.85+00:00

    @Nathan Sokalski
    The link you give does not solve my problem, it still makes only 1 View visible at a time (or part of an adjacent View while sliding, but only 1 while stopped).
    Well, that is pretty much the way ViewPagers work.

    Do you have an example of either a ViewPager or a ViewPager2 that works the way you want?

    I can't say I've done it, but have you considered a horizontal RecyclerView something like this https://medium.com/holler-developers/paging-image-gallery-with-recyclerview-f059d035b7e7

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.