1.导入依赖
//build.gradle 的Project下导入 maven { url 'https://jitpack.io' } //build.gradle 的app下导入 implementation 'com.github.zhpanvip:bannerviewpager:3.5.4'
2.Activity的xml布局
3.编写适配器
//FoodBean是实体类 public class MyBannerViewPager extends baseBannerAdapter{ @Override protected void bindData(baseViewHolder holder, FoodBean.DataBean data, int position, int pageSize) { //加载是图片 Glide.with(Utils.getApp()).load(data.getPic()).transform(new RoundedCorners(80)) .into((ImageView) holder.findViewById(R.id.banner_image)); } //获取item布局 @Override public int getLayoutId(int viewType) { return R.layout.item; } }
4.编写item布局
5.编写属性
mainBanner.setPageStyle(PageStyle.MULTI_PAGE) .setRevealWidth(BannerUtils.dp2px(10)) .setPageMargin(BannerUtils.dp2px(10)) .setIndicatorGravity(IndicatorGravity.CENTER) .setAdapter(new MyBannerViewPager()) //设置适配器 必须 .setIndicatorStyle(IndicatorStyle.ROUND_RECT) .setIndicatorSliderGap(BannerUtils.dp2px(2)) .create(foodBean.getData());
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)