Search in sources :

Example 6 with CircleIndicator

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);
    });
}
Also used : BannerImageAdapter(com.youth.banner.adapter.BannerImageAdapter) ImageAdapter(com.test.banner.adapter.ImageAdapter) CircleIndicator(com.youth.banner.indicator.CircleIndicator) Handler(android.os.Handler) DataBean(com.test.banner.bean.DataBean)

Example 7 with CircleIndicator

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);
}
Also used : ImageTitleAdapter(com.test.banner.adapter.ImageTitleAdapter) CircleIndicator(com.youth.banner.indicator.CircleIndicator) IndicatorConfig(com.youth.banner.config.IndicatorConfig)

Aggregations

CircleIndicator (com.youth.banner.indicator.CircleIndicator)7 ImageAdapter (com.test.banner.adapter.ImageAdapter)5 DataBean (com.test.banner.bean.DataBean)3 ImageTitleAdapter (com.test.banner.adapter.ImageTitleAdapter)2 Banner (com.youth.banner.Banner)2 BannerImageAdapter (com.youth.banner.adapter.BannerImageAdapter)2 IndicatorConfig (com.youth.banner.config.IndicatorConfig)2 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 LinearLayout (android.widget.LinearLayout)1 NonNull (androidx.annotation.NonNull)1 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)1 Fragment (androidx.fragment.app.Fragment)1 FragmentStateAdapter (androidx.viewpager2.adapter.FragmentStateAdapter)1 ViewPager2 (androidx.viewpager2.widget.ViewPager2)1 BindView (butterknife.BindView)1 ButterKnife (butterknife.ButterKnife)1 OnClick (butterknife.OnClick)1 RoundedCorners (com.bumptech.glide.load.resource.bitmap.RoundedCorners)1