1使用代码
banner.setOnBannerListener(new OnBannerListener() {//banner点击事件添加一定要在start前 否则容易导致监听失效
@Override
public void OnBannerClick(int position) {
Intent intent = new Intent(getContext(), NewsWebActivity.class);
intent.putExtra("vcTitle", "新闻");
intent.putExtra("nId", rows.get(position).nId);
intent.putExtra("shareTitle", rows.get(pos).vcTitle);
intent.putExtra("vcJumpLink", rows.get(position).picOnclick);//UrlConstants.ToNewsHtml + rows.get(pos).nId
if (rows.get(position).vcPicUrl == null || rows.get(position).vcPicUrl.isEmpty()) {
intent.putExtra("vcIconUrl", "");
} else {
intent.putExtra("vcIconUrl", rows.get(position).vcPicUrl);
}
startActivity(intent);
}
});
banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
banner.setImageLoader(new GlideImageLoader());
banner.setImages(paths);
banner.setBannerTitles(titls);
banner.setBannerAnimation(Transformer.Default);
banner.setDelayTime(3000);
banner.isAutoPlay(true);
banner.setIndicatorGravity(BannerConfig.RIGHT);
banner.start();
2 布局
<com.youth.banner.Banner
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="152dp"
android:background="@mipmap/bg_main_vp"
android:paddingStart="16dp"
android:paddingEnd="17dp"/>
3 ImageLoader
public class GlideImageLoader extends ImageLoader {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
//Picasso 加载图片简单用法
// Picasso.with(context).load((String) path).error(R.mipmap.ic_error_bg).resize().centerCrop().into(imageView);//.fit()
Glide.with(context).load((String) path).apply(new RequestOptions()
.error(R.mipmap.ic_error_bg)
.centerCrop()
.placeholder(R.mipmap.ic_wait)
).into(imageView);
}
}