banner(最新)

//一定要记得加网络权限

//导入依赖(banner和glide)

implementation 'com.youth.banner:banner:1.4.10'
implementation 'com.github.bumptech.glide:glide:3.+'

//布局文件

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <com.youth.banner.Banner
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:id="@+id/banner"
        ></com.youth.banner.Banner>

</android.support.constraint.ConstraintLayout>

//初始化控件创建集合

//创建集合
list = new ArrayList<>();
list.add( "https://img.huxiucdn.com/article/cover/201809/18/222826635501.jpg?imageView2/1/w/710/h/400/|imageMogr2/strip/interlace/1/quality/85/format/jpg" );
list.add( "https://img.huxiucdn.com/article/cover/201809/19/163742361951.jpg?imageView2/1/w/710/h/400/|imageMogr2/strip/interlace/1/quality/85/format/jpg" );
list.add( "https://img.huxiucdn.com/article/cover/201809/19/084120785414.jpg?imageView2/1/w/710/h/400/|imageMogr2/strip/interlace/1/quality/85/format/jpg" );

    banner.setImageLoader( new GlideImageLoader() );
    banner.setImages( list );
    banner.start();
}

//Glide

public class GlideImageLoader extends ImageLoader {
    @Override
    public void displayImage(Context context, Object path, ImageView imageView) {
        /**
         注意:
         1.图片加载器由自己选择,这里不限制,只是提供几种使用方法
         2.返回的图片路径为Object类型,由于不能确定你到底使用的那种图片加载器,
         传输的到的是什么格式,那么这种就使用Object接收和返回,你只需要强转成你传输的类型就行,
         切记不要胡乱强转!
         */
        //Glide 加载图片简单用法
        Glide.with(context).load(path).into(imageView);
    }

}

猜你喜欢

转载自blog.csdn.net/qq_42250299/article/details/82809759