- 需要添加依赖包
implementation 'com.youth.banner:banner:1.4.10'
2.`public class MainActivity extends AppCompatActivity {
Banner banner;
private List<Integer> images = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initimageviewpager();
}
public void initimageviewpager(){
Log.d("图片轮播函数", "initimageviewpager: ");
images.add(R.drawable.image1);
images.add(R.drawable.image2);
images.add(R.drawable.image3);
banner = findViewById(R.id.banner);
// banner = (Banner)findViewById(R.id.banner);
banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
banner.setImageLoader(new GlideImageLoader());
banner.setImages(images);
banner.setBannerAnimation(Transformer.DepthPage);
banner.isAutoPlay(true);
banner.setDelayTime(3000);
banner.setIndicatorGravity(BannerConfig.CENTER);
banner.start();
Log.d("出图片轮播函数", "initimageviewpager: ");
}
private class GlideImageLoader extends ImageLoader {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
Glide.with(context).load(path).into(imageView);
}
}
}`
来源:CSDN
作者:木 土 硎
链接:https://blog.csdn.net/weixin_43605701/article/details/103915903