I'm designing a view with multiple pages. I want edges of previous and next pages to be show like below and implement a 2 finger swipe to switch between pages.
I tried using ViewPager
with negative page margin as suggested here but that only shows one of the edges on the screen, not both simultaneously.
Alternatively, is there any way i can position part of my view outside screen and then animate it giving it a ViewPager
type effect.
How should I go about it ? Thanks !
To show preview of left and right pages set the following two values
If you need space between two pages in the viewpager then add viewpager.setPageMargin(int)
Android ViewPager - Show preview of page on left and right
Sometime ago I needed such feature and prepared a tiny library which uses
RecyclerView
with PagerSnapHelper (added in version 25.1.0 of the v7 support library) instead of classicViewPager
:MetalRecyclerPagerView - you can find all the code along with examples there.
Mainly it consists of a single class file: MetalRecyclerViewPager.java (and two xmls: attrs.xml and ids.xml).
Hope it helps somebody :)
Download the source code from here(ViewPager with previous and next page boundaries)
MainActivity.java
I have a similar solution:
On the viewpager set left and right padding, e.g. 20dp. Do also set the page margin on the viewpager, e.g. half of the pager padding. And do not forget to disable clip padding.
Set left and right padding for whole item view. Example xml (page_item.xml):
Then set negative page margin for
PageView
equal to 2*(previous view padding)Optional. Set zero left padding for first item and zero right padding to last item to hide empty edges. You may do this in the
PageAdapter
orPage
fragment class.Quoting myself from a blog post on this subject: