The Android Developer Challenge is back! Submit your idea before December 2.

MarginPageTransformer

public final class MarginPageTransformer
extends Object implements ViewPager2.PageTransformer

java.lang.Object
   ↳ androidx.viewpager2.widget.MarginPageTransformer


Adds space between pages via the ViewPager2.PageTransformer API.

Internally relies on View.setTranslationX(float) and View.setTranslationY(float).

Note: translations on pages are not reset when this adapter is changed for another one, so you might want to set them manually to 0 when dynamically switching to another transformer, or when switching ViewPager2 orientation.

Summary

Public constructors

MarginPageTransformer(int marginPx)

Creates a MarginPageTransformer.

Public methods

void transformPage(View page, float position)

Apply a property transformation to the given page.

Inherited methods

Public constructors

MarginPageTransformer

public MarginPageTransformer (int marginPx)

Creates a MarginPageTransformer.

Parameters
marginPx int: non-negative margin

Public methods

transformPage

public void transformPage (View page, 
                float position)

Apply a property transformation to the given page.

Parameters
page View: Apply the transformation to this page

position float: 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 -2 is two pages to the left. Minimum / maximum observed values depend on how many pages we keep attached, which depends on offscreenPageLimit.