banner.setAdapter(new MultipleTypesAdapter(this, DataBean.getTestDataVideo()))
.setIndicator(new NumIndicator(this))
.setIndicatorGravity(IndicatorConfig.Direction.RIGHT)
.setOnBannerListener(new OnBannerListener() {
@OverRide
public void OnBannerClick(Object data, int position) {
Log.e("OnBannerClick", "position");
banner.stop();//点击可以停止轮播
}
})
.addOnPageChangeListener(new OnPageChangeListener() {
@OverRide
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
Log.e("onPageSelected", "" + position);
RecyclerView.ViewHolder viewHolder = ((MultipleTypesAdapter) banner.getAdapter()).getVHMap().get(position);
if (position == 0) {
banner.stop();//无法停止轮播
}
}
因为我现在有个需求就是轮播会有视频和图片,滑动视频页的时候需要停止轮播 等视频播放完成后再次启动轮播,目前是在onPageSelected调用banner.stop()无法停止轮播
9条答案
按热度按时间23c0lvtd1#
用banner.isAutoLoop(false);暂停轮播,因为onPageScrolled执行完后又postDelay了,所以stop无效
e7arh2l62#
我现试过banner.isAutoLoop(false) 还是暂停不成功
mbyulnm03#
banner/banner/src/main/java/com/youth/banner/Banner.java
Lines 392 to 412 in 34eb6e1
| | staticclassAutoLoopTaskimplementsRunnable { |
| | privatefinalWeakReference reference; |
| | |
| | AutoLoopTask(Bannerbanner) { |
| | this.reference = newWeakReference<>(banner); |
| | } |
| | |
| | @Override |
| | publicvoidrun() { |
| | Bannerbanner = reference.get(); |
| | if (banner != null && banner.mIsAutoLoop) { |
| | intcount = banner.getItemCount(); |
| | if (count == 0) { |
| | return; |
| | } |
| | intnext = (banner.getCurrentItem() + 1) % count; |
| | banner.setCurrentItem(next); |
| | banner.postDelayed(banner.mLoopTask, banner.mLoopTime); |
| | } |
| | } |
| | } |
不可能不能成功暂停的,你检查你的代码是不是没有执行isAutoLoop(false)
m3eecexj4#
我也遇到了该问题,设置 isAutoLoop(false)时会停止轮播,但是start和stop 都无法调用。想要设置在哪个item时轮播就不行。
override fun onPageSelected(position: Int) {
/if (videoPath.isNullOrEmpty()) {
banner.isAutoLoop(false)
banner.start()
} else {
if (position == 0) {
banner.isAutoLoop(true)
banner.stop()
videoManager.startPlay(videoPath)
} else {
banner.isAutoLoop(false)
banner.start()
if (videoManager.isPlaying) {
videoManager.stopPlay(true)
}
}
}/
banner.isAutoLoop(true)
banner.stop()
Log.e("addOnPageChangeListener", "onPageSelected: $position")
}
polhcujo5#
if(((DataBean)banner.getAdapter().getData(position)).viewType==2){
RecyclerView.ViewHolder viewHolder = ((MultipleTypesAdapter) banner.getAdapter()).getVHMap().get(position);
Log.e("--", "position:" + position + "VH Type is " + viewHolder.getClass().getCanonicalName());
}
这里第一次轮播的时候 这个viewHolder获取是空的是怎么回事
nhhxz33t6#
首次加载时似乎没有触发onPageSelected的回调 我暂时没找到触发的方式 用了反射方案
val clz = banner::class.java
val field = clz.getDeclaredField("mPageChangeCallback")
field.isAccessible = true
val instance = field.get(banner)
val clzs = clz.declaredClasses
for (subClz in clzs) {
if (subClz.canonicalName == instance::class.java.canonicalName) {
val declaredField = subClz.getDeclaredField("isScrolled")
declaredField.isAccessible = true
declaredField.setBoolean(instance, true)
}
}
来触发onPageSelected的第一次回调
5ktev3wc7#
你这个是在onPageSelected使用吗
mi7gmzs68#
滑动暂停后,再滑回到视频变成黑屏了,没有视频预览了,这个怎么处理呀
xqkwcwgp9#