I have a ViewPager with the PageTransformer implementation that does some funky stuff to the next page of the ViewPager. My implementation looks like this:
class ZoomOutPageTransformer implements ViewPager.PageTransformer {
private static final float MIN_SCALE = 0.85f;
private static final float MIN_ALPHA = 0.5f;
@Override
public void transformPage(View view, float position) {
int pageWidth = view.getWidth();
if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
view.setAlpha(0);
} else if (position <= 0) { // [-1,0]
// Use the default slide transition when moving to the left page
} else if (position < 1) { // (0,1]
do some funky stuff to the page currently being scrolled into the main view on scrolling left
} else if (position==1) {
do some funky stuff to the next page
}
else { // (1,+Infinity]
// This page is way off-screen to the right.
view.setAlpha(1);
}
}
}
The problem is that these transform animations are available as soon as the pager is loaded, but they're not available to the first fragment of my viewpager. I.e. the first time a fragment is loaded, the transformPage
method is not being called. Is there a way to call the transformPage
method manually? I.e. when I'm setting up my ViewPager inside onCreateView
? Or somewhere else?
ViewPager.PageTransformer
only animates transitions between pages. That aside, I don't know how you could do what you want without manually animating (without aPageTransformer
at all).pager.setCurrentItem(1)
;pager.setCurrentItem(0,true);
to trigger the transformPage method. If you have a better way, I'd love to hear it!