ScrollPager
Flip each Fragment using ViewPager
DEMO
The code is commented and easy to understand
First understand how ViewPager animation works
Starting in 3.0, ViewPager began to support custom switch animations, exposing the interface to PageTransformer, So just implement the PageTransformer interface and its only method transformPage(View View, float Position).
public interface PageTransformer {
/**
* Apply a property transformation to the given page.
*
* @param page Apply the transformation to this page
* @param position Position of page relative to the current front-and-center
* position of the pager. 0 is front and center. 1 is one full
* page position to the right, and -1 is one page position to the left.
*/
public void transformPage(View page, float position);
}Copy the code
- Parameter Position Indicates the offset of the given interface position with respect to the center of the screen. As the user slides through the interface, it changes dynamically. We can then apply the value of position to the setAlpha(), setTranslationX(), or setScaleY() methods to achieve a custom animation effect. When a ViewPager slides, any Page in memory that is alive performs a transformPage method. The slide involves two pages, the current Page and the next Page, and their position values are opposite (one slides in and one slides out). For example, Slide page A to the right halfway to the screen, and page B is exactly halfway there, so the positions of A and B are 0.5 and -0.5 position == 0: position == 1 when the current interface is in the center of the screen: Position == -1: The current Page just slides out to the left of the screen