通用的广告栏控件,让你轻松实现广告头效果。支持无限循环,可以设置自动翻页和时间(而且非常智能,手指触碰则暂停翻页,离开自动开始翻页。你也可以设置在界面onPause的时候不进行自动翻页,onResume之后继续自动翻页),并且提供多种翻页特效(依赖view-pager-transforms)。 对比其他广告栏控件,大多都需要对源码进行改动才能加载网络图片,或者帮你集成不是你所需要的图片缓存库。而这个库能让有代码洁癖的你欢喜,不需要对库源码进行修改你就可以使用任何你喜欢的网络图片库进行配合。
使用方法介绍:
配置依赖库,可以使moudle依赖,可以gradle依赖,compile'com.bigkoo:convenientbanner:2.0.5'
xml配置:
<com.bigkoo.convenientbanner.ConvenientBanner xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/convenientBanner" android:layout_width="match_parent" android:layout_height="200dp" app:canLoop="true"/>或者代码中动态添加:
ConvenientBanner mConvenientBanner = new ConvenientBanner(this,false); mConvenientBanner.setMinimumHeight(500); mConvenientBanner.setPages( new CBViewHolderCreator<LocalImageHolderView>() { @Override public LocalImageHolderView createHolder() { return new LocalImageHolderView(); } }, localImages) //设置两个点图片作为翻页指示器,不设置则没有指示器,可以根据自己需求自行配合自己的指示器,不需要圆点指示器可用不设 .setPageIndicator(new int[]{R.drawable.ic_page_indicator, R.drawable.ic_page_indicator_focused}) //设置指示器的方向 .setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.ALIGN_PARENT_RIGHT) .setOnItemClickListener(this);
多种动画切换特效使用的viewpagertransforms开源,viewpager切换实用的Loopingviewpager开源代码convenientBanner.setManualPageable(false);//设置不能手动影响listView.addHeaderView(mConvenientBanner);
github源码地址:
https://github.com/saiwu-bigkoo/Android-ConvenientBanner
https://github.com/ToxicBakery/ViewPagerTransforms
https://github.com/imbryk/LoopingViewPager