Skip to content

Commit

Permalink
添加需求:在代码中可以设置是否可以自动轮播
Browse files Browse the repository at this point in the history
  • Loading branch information
pinguo-zhouwei committed Jun 9, 2018
1 parent d3d4a3e commit cc138b6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Movie>());
List<Movie> movies = new ArrayList<>();
movies.add(mMovies.get(0));
movies.add(mMovies.get(1));
mMZBannerView.setCanLoop(false);
setBanner(movies);

}
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/remote_test_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 13 additions & 1 deletion mzbanner/src/main/java/com/zhouwei/mzbanner/MZBannerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ public void start(){
return;
}
if(mIsCanLoop){
pause();
mIsAutoPlay = true;
mHandler.postDelayed(mLoopRunnable,mDelayedTime);
}
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit cc138b6

Please sign in to comment.