ViewPagerAdapter pagerAdapter = new ViewPagerAdapter();
//设置足够大伪无限循环
MAX_PAGE_COUNT = Integer.MAX_VALUE;
//确保显示页面为第一页,否则可能显示中间的某页可能会比较怪异
int halpCount = MAX_PAGE_COUNT / 2 + (size - ((MAX_PAGE_COUNT / 2) % size));
Field field = null;
try {
field = ViewPager.class.getDeclaredField("mRestoredCurItem");
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
field.setAccessible(true);
try {
//halpCount 为我们想要的第一次就展示的页面halpCount
field.set(vp_head, halpCount);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
vp_head.setAdapter(pagerAdapter);
vp_head.setCurrentItem(halpCount);
ViewPager无限循环空白页问题解决
最新推荐文章于 2022-07-07 10:22:25 发布