use of com.youth.banner.indicator.CircleIndicator in project banner by youth5201314.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
// 自定义的图片适配器,也可以使用默认的BannerImageAdapter
ImageAdapter adapter = new ImageAdapter(DataBean.getTestData2());
banner.setAdapter(adapter).addBannerLifecycleObserver(// 添加生命周期观察者
this).setIndicator(// 设置指示器
new CircleIndicator(this)).setOnBannerListener((data, position) -> {
Snackbar.make(banner, ((DataBean) data).title, Snackbar.LENGTH_SHORT).show();
LogUtils.d("position:" + position);
});
// 添加item之间切换时的间距(如果使用了画廊效果就不要添加间距了,因为内部已经添加过了)
// banner.addPageTransformer(new MarginPageTransformer( BannerUtils.dp2px(10)));
// 和下拉刷新配套使用
refresh.setOnRefreshListener(() -> {
// 模拟网络请求需要3秒,请求完成,设置setRefreshing 为false
new Handler().postDelayed(() -> {
refresh.setRefreshing(false);
// 给banner重新设置数据
banner.setDatas(DataBean.getTestData());
// 对setDatas()方法不满意?你可以自己在adapter控制数据,参考setDatas()的实现修改
// adapter.updateData(DataBean.getTestData());
// banner.setCurrentItem(banner.getStartPosition(), false);
// banner.setIndicatorPageChange();
}, 3000);
});
}
use of com.youth.banner.indicator.CircleIndicator in project banner by youth5201314.
the class ConstraintLayoutBannerActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_constraint_layout_banner);
ButterKnife.bind(this);
banner.setAdapter(new ImageTitleAdapter(DataBean.getTestData()));
banner.setIndicator(new CircleIndicator(this));
banner.setIndicatorSelectedColorRes(R.color.main_color);
banner.setIndicatorGravity(IndicatorConfig.Direction.RIGHT);
banner.setIndicatorMargins(new IndicatorConfig.Margins(0, 0, BannerConfig.INDICATOR_MARGIN, (int) BannerUtils.dp2px(12)));
banner.addBannerLifecycleObserver(this);
}
Aggregations