我想在我的 ViewPager https://raw.githubusercontent.com/bhaveshjabuvani88/CarouselEffect/master/CarouselEffectDemo.gif中实现这个动画
一切正常,直到我尝试从 ViewPager 中删除视图。
我在 ViewPager 中有 3 页。当我删除第 N2 页时transformPage(View view, float position)
,第 N1 页和第 N3 页的位置变为 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);
}
}