build中的引用
//banner轮播框架
implementation 'com.youth.banner:banner:1.4.10'
布局中的引用
<com.youth.banner.Banner
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_90"
android:layout_marginBottom="@dimen/dp_10" />
fragment和activity中的设置
private void setBanner(List<AdListBean.DataBean> data) {
List<String> imgeList = new ArrayList<>();
List<String> title = new ArrayList<>();
for (AdListBean.DataBean banner : data) {
imgeList.add(banner.getImg_url());
title.add("");
}
headBannerBinding.banner.setImageLoader(new ImageLoader() {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
GlideUtil.setPic(path + "", imageView);
}
});
headBannerBinding.banner.setBannerAnimation(Transformer.Accordion);
headBannerBinding.banner.setImages(imgeList);
headBannerBinding.banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
headBannerBinding.banner.setIndicatorGravity(BannerConfig.CENTER);
headBannerBinding.banner.setDelayTime(3000);
headBannerBinding.banner.start();
//banner的点击事件
headBannerBinding.banner.setOnBannerListener(new OnBannerListener() {
@Override
public void OnBannerClick(int position) {
ToastUtils.showToast(position + "----");
}
});
}