Android 简单实现XBanner无限轮播

在项目build.gradle

maven { url 'https://jitpack.io' }

在model中的build.gradle导入依赖

implementation 'com.github.xiaohaibin:XBanner:1.6.1'

布局文件:

	

activity中在获取数据成功的方法中调用:

  @Override
    public void BannerSuccess(BannerEntity bannerEntity) {
        ArrayList images = new ArrayList<>();
        final List result = bannerEntity.getResult();
        for (int i = 0; i < result.size(); i++) {
            images.add(result.get(i).getImageUrl());
        }
        if (images != null) {
            banner.setData(result,null);
            banner.loadImage(new XBanner.XBannerAdapter() {
                @Override
                public void loadBanner(XBanner banner, Object model, View view, int position) {
                    Picasso.with(getApplication()).load(result.get(position).getImageUrl()).into((ImageView) view);
                }
            });
        }
        //横向移动
        banner.setPageTransformer(Transformer.Default);
    }

你可能感兴趣的:(原创)