在activity中banner的使用:
banner.setImages(list)
.setBannerAnimation(Transformer.Default)
.setImageLoader(new GlideImageLoader(activity))
.setBannerStyle(BannerConfig.CIRCLE_INDICATOR)
.setIndicatorGravity(BannerConfig.CENTER)
.isAutoPlay(true)
.setDelayTime(3300)
.start();
//banner点击事件
banner.setOnBannerClickListener(new OnBannerClickListener() {
@Override
public void OnBannerClick(int position) {
//循环拿出type
for (int i = 0; i < bean.getData().size(); i++) {
//判断type是0还是1
if (bean.getData().get(i).getType() == 0) {
//是0的话进行跳转
//不是则进行吐司
} else if (bean.getData().get(i).getType() == 1) {
Toast.makeText(MainActivity.this, "我要跳转到商品详情页", Toast.LENGTH_SHORT).show();
}
}
}
});
在布局中banner的使用:
<com.youth.banner.Banner
android:id="@+id/banner_bottom"
android:layout_width=“match_parent”
android:layout_height=“match_parent”
app:image_scale_type=“fit_xy”
app:indicator_drawable_selected="@mipmap/banner_select"
app:indicator_drawable_unselected="@mipmap/banner_default"
app:indicator_height=“12px”
app:indicator_width=“24px”
app:layout_constraintLeft_toLeftOf=“parent”
app:layout_constraintRight_toRightOf=“parent”
app:layout_constraintTop_toTopOf=“parent”></com.youth.banner.Banner>