From bf521ba1c3c7191daa7c897d25ec4263ab6eaa6d Mon Sep 17 00:00:00 2001 From: zhouwei Date: Sat, 10 Jun 2017 08:16:15 +0800 Subject: [PATCH] =?UTF-8?q?bug=20fix=EF=BC=9Afix=20=20=E4=BB=8E=E7=BD=91?= =?UTF-8?q?=E4=B8=8A=E8=8E=B7=E5=8F=96=E6=95=B0=E6=8D=AE=E5=90=8E=E5=B1=95?= =?UTF-8?q?=E7=A4=BAbanner=20ANR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/zhouwei/mzbanner/MZBannerView.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mzbanner/src/main/java/com/zhouwei/mzbanner/MZBannerView.java b/mzbanner/src/main/java/com/zhouwei/mzbanner/MZBannerView.java index bbb63b5..b457fa3 100644 --- a/mzbanner/src/main/java/com/zhouwei/mzbanner/MZBannerView.java +++ b/mzbanner/src/main/java/com/zhouwei/mzbanner/MZBannerView.java @@ -413,6 +413,7 @@ public static class MZPagerAdapter extends PagerAdapter{ private ViewPager mViewPager; private boolean canLoop; private BannerPageClickListener mPageClickListener; + private final int mLooperCountFactor = 500; public MZPagerAdapter(List datas, MZHolderCreator MZHolderCreator,boolean canLoop) { if(mDatas == null){ @@ -447,7 +448,7 @@ public void setUpViewViewPager(ViewPager viewPager){ private int getStartSelectItem(){ // 我们设置当前选中的位置为Integer.MAX_VALUE / 2,这样开始就能往左滑动 // 但是要保证这个值与getRealPosition 的 余数为0,因为要从第一页开始显示 - int currentItem = Integer.MAX_VALUE / 2; + int currentItem = getRealCount() * mLooperCountFactor / 2; if(currentItem % getRealCount() ==0 ){ return currentItem; } @@ -464,7 +465,9 @@ public void setDatas(List datas) { @Override public int getCount() { - return canLoop ?Integer.MAX_VALUE : getRealCount();//ViewPager返回int 最大值 + // 2017.6.10 bug fix + // 如果getCount 的返回值为Integer.MAX_VALUE 的话,那么在setCurrentItem的时候会ANR(除了在onCreate 调用之外) + return canLoop ? getRealCount() * mLooperCountFactor : getRealCount();//ViewPager返回int 最大值 } @Override