I want to implement this animation in my ViewPager https://raw.githubusercontent.com/bhaveshjabuvani88/CarouselEffect/master/CarouselEffectDemo.gif
Everything works fine until I try to remove view from ViewPager.
I have 3 pages in ViewPager. When I'm removing page N2, position in transformPage(View view, float position) for page N1 and page N3 is becoming 0.0.
Therefore, the position for center page (page N3) is becoming negative:
position -= parent.getPaddingRight() / (float) pageWidth;
and center page is scaling down.
Can you help to fix this problem ?
public void transformPage(View view, float position) {
int pageWidth = view.getWidth();
int pageHeight = view.getHeight();
// FIX issue: https://code.google.com/p/android/issues/detail?id=64046
ViewPager parent = (ViewPager) view.getParent();
position -= parent.getPaddingRight() / (float) pageWidth;
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.
if (position >= -1 && position <= 1) {
view.setAlpha(MIN_ALPHA + (scaleFactor - MIN_SCALE) / (1 - MIN_SCALE) * (1 - MIN_ALPHA));
} else {
view.setAlpha(1F);
}
}