ViewPager with previous and next page boundaries

android, android-viewpager, viewanimator, viewflipper

Solution

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 the `ViewPager` and calls `setClipChildren(false);` on itself, so even though the `ViewPager` is focused on one selected page, other pages that have coordinates beyond the `ViewPager` bounds are still visible, so long as they fit within the `PagerContainer`. By sizing the `ViewPager` to be smaller than the `PagerContainer`, the `ViewPager` 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, as `ViewPager` will only handle swipe events on its own visible bounds, ignoring any pages visible to the sides.

Problem

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 !

Original source

Related problems