MarginPageTransformer

public final class MarginPageTransformer implements ViewPager2.PageTransformer


Adds space between pages via the ViewPager2.PageTransformer API.

Internally relies on setTranslationX and setTranslationY.

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(@Px int marginPx)

Creates a MarginPageTransformer.

Public methods

void
transformPage(@NonNull View page, float position)

Apply a property transformation to the given page.

Public constructors

MarginPageTransformer

Added in 1.0.0
public MarginPageTransformer(@Px int marginPx)

Creates a MarginPageTransformer.

Parameters
@Px int marginPx

non-negative margin

Public methods

transformPage

Added in 1.1.0-beta03
public void transformPage(@NonNull View page, float position)

Apply a property transformation to the given page.

Parameters
@NonNull View page

Apply the transformation to this page

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