第一次setPageTransformer
之后可以正常使用,但是当notifyDataSetChanged
之后,其显示就有问题。但是只要viewpager
一滑动,PageTransformer
的效果就有了。
正常情况下我设置的PageTransformer
是这样的,两边没有显示的比较小,而当前位置的显示大:
但是当notifyDataSetChanged
之后,显示效果成这个样子了:
不过只要有滑动,显示效果又没问题了。
这是个什么情况,要如何notifyDataSetChanged
之后就可以显示PageTransformer
的效果?
下面是我的PageTransformer
的代码(个人感觉这个代码是没有问题的):
private class Transformer implements ViewPager.PageTransformer {
private final float MIN_SCALE = 0.8f;
@Override
public void transformPage(View page, float position) {
if(position >= -1 && position <= 1) {
page.setScaleX(1.0f - Math.abs(position) * (1 - MIN_SCALE));
page.setScaleY(1.0f - Math.abs(position) * (1 - MIN_SCALE));
} else {
page.setScaleX(MIN_SCALE);
page.setScaleY(MIN_SCALE);
}
}
}
No problem with mine. How did you notifyDataSetChanged?
Has the original poster solved it?
Has the poster’s problem been solved? This happens to me too
Has the original poster solved it? Encountering this problem now too. Solved by the following method, it feels stupid
mViewPager.setCurrentItem(1);
mViewPager.setCurrentItem(0);
mViewPager.invalidate();
ResetAdapter