Search in sources :

Example 1 with DataBean

use of com.test.banner.bean.DataBean in project banner by youth5201314.

the class MainActivity method click.

@OnClick({ R.id.style_image, R.id.style_image_title, R.id.style_image_title_num, R.id.style_multiple, R.id.style_net_image, R.id.change_indicator, R.id.rv_banner, R.id.cl_banner, R.id.vp_banner, R.id.banner_video, R.id.banner_tv, R.id.gallery, R.id.topLine })
public void click(View view) {
    indicator.setVisibility(View.GONE);
    switch(view.getId()) {
        case R.id.style_image:
            refresh.setEnabled(true);
            banner.setAdapter(new ImageAdapter(DataBean.getTestData()));
            banner.setIndicator(new CircleIndicator(this));
            banner.setIndicatorGravity(IndicatorConfig.Direction.CENTER);
            break;
        case R.id.style_image_title:
            refresh.setEnabled(true);
            banner.setAdapter(new ImageTitleAdapter(DataBean.getTestData()));
            banner.setIndicator(new CircleIndicator(this));
            banner.setIndicatorGravity(IndicatorConfig.Direction.RIGHT);
            banner.setIndicatorMargins(new IndicatorConfig.Margins(0, 0, BannerConfig.INDICATOR_MARGIN, BannerUtils.dp2px(12)));
            break;
        case R.id.style_image_title_num:
            refresh.setEnabled(true);
            // 这里是将数字指示器和title都放在adapter中的,如果不想这样你也可以直接设置自定义的数字指示器
            banner.setAdapter(new ImageTitleNumAdapter(DataBean.getTestData()));
            banner.removeIndicator();
            break;
        case R.id.style_multiple:
            refresh.setEnabled(true);
            banner.setIndicator(new CircleIndicator(this));
            banner.setAdapter(new MultipleTypesAdapter(this, DataBean.getTestData()));
            break;
        case R.id.style_net_image:
            refresh.setEnabled(false);
            // 方法一:使用自定义图片适配器
            // banner.setAdapter(new ImageNetAdapter(DataBean.getTestData3()));
            // 方法二:使用自带的图片适配器
            banner.setAdapter(new BannerImageAdapter<DataBean>(DataBean.getTestData3()) {

                @Override
                public void onBindView(BannerImageHolder holder, DataBean data, int position, int size) {
                    // 图片加载自己实现
                    Glide.with(holder.itemView).load(data.imageUrl).thumbnail(Glide.with(holder.itemView).load(R.drawable.loading)).apply(RequestOptions.bitmapTransform(new RoundedCorners(30))).into(holder.imageView);
                }
            });
            banner.setIndicator(new RoundLinesIndicator(this));
            banner.setIndicatorSelectedWidth(BannerUtils.dp2px(15));
            break;
        case R.id.change_indicator:
            indicator.setVisibility(View.VISIBLE);
            // 在布局文件中使用指示器,这样更灵活
            banner.setIndicator(indicator, false);
            banner.setIndicatorSelectedWidth(BannerUtils.dp2px(15));
            break;
        case R.id.gallery:
            startActivity(new Intent(this, GalleryActivity.class));
            break;
        case R.id.rv_banner:
            startActivity(new Intent(this, RecyclerViewBannerActivity.class));
            break;
        case R.id.cl_banner:
            startActivity(new Intent(this, ConstraintLayoutBannerActivity.class));
            break;
        case R.id.vp_banner:
            startActivity(new Intent(this, Vp2FragmentRecyclerviewActivity.class));
            break;
        case R.id.banner_video:
            startActivity(new Intent(this, VideoActivity.class));
            break;
        case R.id.banner_tv:
            startActivity(new Intent(this, TVActivity.class));
            break;
        case R.id.topLine:
            startActivity(new Intent(this, TouTiaoActivity.class));
            break;
    }
}
Also used : RoundLinesIndicator(com.youth.banner.indicator.RoundLinesIndicator) Vp2FragmentRecyclerviewActivity(com.test.banner.ui.Vp2FragmentRecyclerviewActivity) ImageTitleAdapter(com.test.banner.adapter.ImageTitleAdapter) TouTiaoActivity(com.test.banner.ui.TouTiaoActivity) VideoActivity(com.test.banner.ui.VideoActivity) Intent(android.content.Intent) RoundedCorners(com.bumptech.glide.load.resource.bitmap.RoundedCorners) GalleryActivity(com.test.banner.ui.GalleryActivity) IndicatorConfig(com.youth.banner.config.IndicatorConfig) ImageTitleNumAdapter(com.test.banner.adapter.ImageTitleNumAdapter) BannerImageHolder(com.youth.banner.holder.BannerImageHolder) TVActivity(com.test.banner.ui.TVActivity) DataBean(com.test.banner.bean.DataBean) RecyclerViewBannerActivity(com.test.banner.ui.RecyclerViewBannerActivity) MultipleTypesAdapter(com.test.banner.adapter.MultipleTypesAdapter) BannerImageAdapter(com.youth.banner.adapter.BannerImageAdapter) ImageAdapter(com.test.banner.adapter.ImageAdapter) ConstraintLayoutBannerActivity(com.test.banner.ui.ConstraintLayoutBannerActivity) CircleIndicator(com.youth.banner.indicator.CircleIndicator) OnClick(butterknife.OnClick)

Example 2 with DataBean

use of com.test.banner.bean.DataBean 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)

Aggregations

ImageAdapter (com.test.banner.adapter.ImageAdapter)2 DataBean (com.test.banner.bean.DataBean)2 BannerImageAdapter (com.youth.banner.adapter.BannerImageAdapter)2 CircleIndicator (com.youth.banner.indicator.CircleIndicator)2 Intent (android.content.Intent)1 Handler (android.os.Handler)1 OnClick (butterknife.OnClick)1 RoundedCorners (com.bumptech.glide.load.resource.bitmap.RoundedCorners)1 ImageTitleAdapter (com.test.banner.adapter.ImageTitleAdapter)1 ImageTitleNumAdapter (com.test.banner.adapter.ImageTitleNumAdapter)1 MultipleTypesAdapter (com.test.banner.adapter.MultipleTypesAdapter)1 ConstraintLayoutBannerActivity (com.test.banner.ui.ConstraintLayoutBannerActivity)1 GalleryActivity (com.test.banner.ui.GalleryActivity)1 RecyclerViewBannerActivity (com.test.banner.ui.RecyclerViewBannerActivity)1 TVActivity (com.test.banner.ui.TVActivity)1 TouTiaoActivity (com.test.banner.ui.TouTiaoActivity)1 VideoActivity (com.test.banner.ui.VideoActivity)1 Vp2FragmentRecyclerviewActivity (com.test.banner.ui.Vp2FragmentRecyclerviewActivity)1 IndicatorConfig (com.youth.banner.config.IndicatorConfig)1 BannerImageHolder (com.youth.banner.holder.BannerImageHolder)1