Q:

PageTransformer for handling the "centered" Page

I have a ViewPager which is showing 3 different pages. I would like to animate the Pager by using the ZoomOutPageTransformer from an example of Google:
public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
    private static float MIN_SCALE = 0.85f;
    private static float MIN_ALPHA = 0.5f;

    public void transformPage(View view, float position) {
        int pageWidth = view.getWidth();
        int pageHeight = view.getHeight();
        int pageOffset = 1; //one page offset

        if (position < -1) { // [-Infinity,-2)
            // This page is way off-screen to the left.
            view.setAlpha(0);

        } else if (position <= 1) { // [-1,1]
            // Modify the default slide transition to shrink the page as well
            float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
            float vertMargin = pageHeight * (1 - scaleFactor) / 2;
            float horzMargin = pageWidth * (1 - scaleFactor) / 2;
            if (position < 0) {
                view.setTranslationX(horzMargin - vertMargin / 2);
            } else {
                view.setTranslationX(-horzMargin + vertMargin / 2);
            }

            // Scale the page down (between MIN_SCALE and 1)
            view.setScaleX(scaleFactor);
            view.setScaleY(scaleFactor);

            // Fade the page relative to its size.
            view.setAlpha(MIN_ALPHA +
                    (scaleFactor - MIN_SCALE) /
                    (1 - MIN_SCALE) * (1 - MIN_ALPHA));

        } else { // (1,+Infinity]
            // This page is way off-screen to the right.
            view.setAlpha(0);
        }
    }

I've added the variable "pageOffset". What I now want to get is to animate not the first page, but the second (centered) page. So I have to move the whole animation one step to the right. Then the centered page would be "bigger" and more visible than the other pages.
However I'm not able to do this. I tried to change position to position+offset without success. What should I do in this snippet to get my desired result?
Edit: I thought this would work - but however, it doesn't:
public void transformPage(View view, float position) {
  int pageWidth = view.getWidth();
  int pageHeight = view.getHeight();
  int pageOffset = 1; //one page offset

if (position < -1 - pageOffset) { // [-Infinity,-2)
    // This page is way off-screen to the left.
    view.setAlpha(0);

} else if (position - pageOffset <= 1) { // [-1,1]
    // Modify the default slide transition to shrink the page as well
    float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position - pageOffset));
    float vertMargin = pageHeight * (1 - scaleFactor) / 2;
    float horzMargin = pageWidth * (1 - scaleFactor) / 2;
    if (position - pageOffset < 0) {
        view.setTranslationX(horzMargin - vertMargin / 2);
    } else {
        view.setTranslationX(-horzMargin + vertMargin / 2);
    }

    // Scale the page down (between MIN_SCALE and 1)
    view.setScaleX(scaleFactor);
    view.setScaleY(scaleFactor);

    // Fade the page relative to its size.
    view.setAlpha(MIN_ALPHA +
            (scaleFactor - MIN_SCALE) /
            (1 - MIN_SCALE) * (1 - MIN_ALPHA));

} else { // (1,+Infinity]
    // This page is way off-screen to the right.
    view.setAlpha(0);
}

}

A:

I'm not entirely sure your intent, since pageOffset is set to 1 and never updated. That said, perhaps an explanation of my understanding of PageTransformer will shed some light:

   if (mPageTransformer != null) {
        final int scrollX = getScrollX();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();

            if (lp.isDecor) continue;

            final float transformPos = (float) (child.getLeft() - scrollX) / getClientWidth();
            mPageTransformer.transformPage(child, transformPos);
        }
    }

This is a snippet taken from the onPageScrolled method of ViewPager. Within the transformPage method you should use the position argument to determine what animation to apply as shown in the ZoomOutPageTransformer provided:
if (position < -1) // This view is leftward beyond visibility.
else if (position <= 1) // This is our center view being scrolled into visibility.
else // This view is rightward beyond visibility.

As another example:
    @Override
    public void transformPage(View page, float position) {
        if (position >= 0) {
            page.setAlpha(Math.abs(Math.abs(position) - 1));
        }
    }

This method might get called up to three times depending on the situation. Let's look at the case where we have three views and are scrolling from the leftmost (0) to the middle (1). If we are halfway through the transition, Math.abs(Math.abs(position) - 1) will be 0.5 for both views ||±0.5| - 1| = 0.5. In this way, we would apply an opacity of 50% to both views.

