From cc138b634b177815b679ed07a4748359ee708303 Mon Sep 17 00:00:00 2001 From: pinguo-zhouwei Date: Sat, 9 Jun 2018 19:12:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=9C=80=E6=B1=82=EF=BC=9A?= =?UTF-8?q?=E5=9C=A8=E4=BB=A3=E7=A0=81=E4=B8=AD=E5=8F=AF=E4=BB=A5=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=98=AF=E5=90=A6=E5=8F=AF=E4=BB=A5=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=BD=AE=E6=92=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mzbannerview/remote/RemoteTestFragment.java | 12 +++++++++++- app/src/main/res/layout/remote_test_layout.xml | 2 +- .../java/com/zhouwei/mzbanner/MZBannerView.java | 14 +++++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/zhouwei/mzbannerview/remote/RemoteTestFragment.java b/app/src/main/java/com/zhouwei/mzbannerview/remote/RemoteTestFragment.java index 11eeaca..f03be4e 100644 --- a/app/src/main/java/com/zhouwei/mzbannerview/remote/RemoteTestFragment.java +++ b/app/src/main/java/com/zhouwei/mzbannerview/remote/RemoteTestFragment.java @@ -125,9 +125,19 @@ public void onClick(View v) { List movies = new ArrayList(mMovies); movies.add(mMovies.get(0)); movies.add(mMovies.get(1)); + if(movies.size()>2){ + mMZBannerView.setCanLoop(true); + }else{ + mMZBannerView.setCanLoop(false); + } setBanner(movies); }else if(v.getId() == R.id.btn_clear){ - setBanner(new ArrayList()); + List movies = new ArrayList<>(); + movies.add(mMovies.get(0)); + movies.add(mMovies.get(1)); + mMZBannerView.setCanLoop(false); + setBanner(movies); + } } diff --git a/app/src/main/res/layout/remote_test_layout.xml b/app/src/main/res/layout/remote_test_layout.xml index 2960116..6f660d0 100644 --- a/app/src/main/res/layout/remote_test_layout.xml +++ b/app/src/main/res/layout/remote_test_layout.xml @@ -40,7 +40,7 @@ android:layout_height="50dp" android:layout_gravity="center_horizontal" android:layout_marginTop="50dp" - android:text="清空Banner数据" + android:text="减少数目更新" android:padding="10dp" android:gravity="center" android:textColor="@android:color/white" diff --git a/mzbanner/src/main/java/com/zhouwei/mzbanner/MZBannerView.java b/mzbanner/src/main/java/com/zhouwei/mzbanner/MZBannerView.java index 26605da..a3c0a78 100644 --- a/mzbanner/src/main/java/com/zhouwei/mzbanner/MZBannerView.java +++ b/mzbanner/src/main/java/com/zhouwei/mzbanner/MZBannerView.java @@ -288,6 +288,7 @@ public void start(){ return; } if(mIsCanLoop){ + pause(); mIsAutoPlay = true; mHandler.postDelayed(mLoopRunnable,mDelayedTime); } @@ -301,6 +302,17 @@ public void pause(){ mHandler.removeCallbacks(mLoopRunnable); } + /** + * 设置是否可以轮播 + * @param canLoop + */ + public void setCanLoop(boolean canLoop){ + mIsCanLoop = canLoop; + if(!canLoop){ + pause(); + } + } + /** * 设置BannerView 的切换时间间隔 * @param delayedTime @@ -426,7 +438,7 @@ public void onPageSelected(int position) { mIndicators.get(i).setImageResource(mIndicatorRes[0]); } } - // 不能直接将mOnPageChangeListener 设置给ViewPager ,否则拿到的position 是原始的positon + // 不能直接将mOnPageChangeListener 设置给ViewPager ,否则拿到的position 是原始的position if(mOnPageChangeListener!=null){ mOnPageChangeListener.onPageSelected(realSelectPosition); }