我想在ViewPager中实现此动画 https://raw.githubusercontent.com/bhaveshjabuvani88/CarouselEffect/master/CarouselEffectDemo.gif
一切正常,直到我尝试从ViewPager中删除视图。
我在ViewPager中有3页。当我删除页面N2时,页面N1和页面N3在transformPage(View view, float position)
中的位置将变为0.0。
因此,中心页(第N3页)的位置变为负数:
position -= parent.getPaddingRight() / (float) pageWidth;
和中心页面正在缩小。
您能帮助解决此问题吗?
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);
}
}