banner实现无限轮播

时间:2022-07-11 10:11:32
  compile 'com.youth.banner:banner:+'


compile 'com.github.bumptech.glide:glide:3.7.0'
public class MainActivity extends AppCompatActivity {
private Banner banner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

banner = (Banner) findViewById(R.id.banner_id);

//本地图片数据(资源文件)
List<Integer> list = new ArrayList<>();
list.add(R.drawable.a1);
list.add(R.drawable.a2);
list.add(R.drawable.a3);

banner.setImages(list)
.setImageLoader(new GlideImageLoader())
.isAutoPlay(true)
.setDelayTime(1500)
.start();
}
}
 
 
public class GlideImageLoader extends ImageLoader {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
//具体方法内容自己去选择,次方法是为了减少banner过多的依赖第三方包,所以将这个权限开放给使用者去选择
Glide.with(context.getApplicationContext())
.load(path)
.into(imageView);


}

}

 
<com.youth.banner.Banner
android:id="@+id/banner_id"
android:layout_width="match_parent"
android:layout_height="170dp"></com.youth.banner.Banner>