Banner加载网络接口图片

首先导入依赖

implementation 'com.youth.banner:banner:1.4.9'

Xml布局中写


        

图片接口

String[] urls = {"https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2310514390,3580363630&fm=27&gp=0.jpg",
            "https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=756318500,1648332548&fm=27&gp=0.jpg",
            "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=764856423,3994964277&fm=27&gp=0.jpg",
            "https://img-my.csdn.net/uploads/201407/26/1406383265_8550.jpg",
            "http://img4.imgtn.bdimg.com/it/u=1956283034,3979465440&fm=200&gp=0.jpg",
            "http://img1.imgtn.bdimg.com/it/u=232043804,3867273473&fm=26&gp=0.jpg"};

先获取ImageLoader的初始化
然后在使用

 //获取image的实例
        instance = ImageLoader.getInstance();

设置


        banner.setImageLoader(new com.youth.banner.loader.ImageLoader() {
            @Override
            public void displayImage(Context context, Object path, ImageView imageView) {
            instance.displayImage((String) path,imageView);
            }
        });
      

banner设置

        banner.setImages(Arrays.asList(urls));   

最重要的是别忘了运行

        banner.start();

你可能感兴趣的:(Android,APP开发)