1、添加依赖
compile 'com.youth.banner:banner:1.4.9'
compile 'com.github.bumptech.glide:glide:3.7.0'
2、创建ImageLoaderBanner类,继承ImageLoader
public class ImageLoaderBanner extends ImageLoader {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
//Glide设置图片的简单用法
Glide.with(context).load(pa
th).into(imageView);
}
}
3、MainActivity.Java设置图片加载器
banner.setImageLoader(new ImageLoaderBanner());
list = new ArrayList<String>();
list.add(img1);
list.add(img2);
list.add(img3);
list.add(img4);
//设置集合
banner.setImages(list);
//banner执行完方法之后调用
banner.start();
如果想要实现小圆点,需要在布局文件中添加属性
<com.youth.banner.Banner
android:id="@+id/myBanner"
android:layout_width="match_parent"
android:layout_height="200dp"
//布局文件中设置小圆点的大小
app:indicator_height="20dp"
app:indicator_width="20dp"
>
</com.youth.banner.Banner>