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 !
Quoting myself from a blog post on this subject:
The third approach comes from Dave Smith, co-author of the well-regarded book Android Recipes. He went in a very different direction, using a custom container that disabled children clipping to show more than one page at a time.
His published sample code shows the whole thing in action. His container (
com.example.pagercontainer.PagerContainer
) wraps theViewPager
and callssetClipChildren(false);
on itself, so even though theViewPager
is focused on one selected page, other pages that have coordinates beyond theViewPager
bounds are still visible, so long as they fit within thePagerContainer
. By sizing theViewPager
to be smaller than thePagerContainer
, theViewPager
can size its pages to that size, leaving room for other pages to be seen.PagerContainer
, though, needs to help out a bit with touch events, asViewPager
will only handle swipe events on its own visible bounds, ignoring any pages visible to the sides.