Search in sources :

Example 1 with CircleIndicator

use of com.youth.banner.indicator.CircleIndicator in project banner by youth5201314.

the class Vp2FragmentRecyclerviewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_vp2_fragment_recyclerview);
    ButterKnife.bind(this);
    viewPager2.setAdapter(new FragmentStateAdapter(this) {

        @NonNull
        @Override
        public Fragment createFragment(int position) {
            if (position == 0) {
                return BannerListFragment.newInstance(position);
            } else if (position == 1) {
                return BlankFragment.newInstance();
            } else {
                return BannerFragment.newInstance();
            }
        }

        @Override
        public int getItemCount() {
            return 3;
        }
    });
    new TabLayoutMediator(mTabLayout, viewPager2, (tab, position) -> {
        tab.setText("页面" + position);
    }).attach();
    mBanner.addBannerLifecycleObserver(this).setAdapter(new ImageAdapter(DataBean.getTestData())).setIntercept(false).setIndicator(new CircleIndicator(this));
}
Also used : R(com.test.banner.R) Bundle(android.os.Bundle) TabLayout(com.google.android.material.tabs.TabLayout) ButterKnife(butterknife.ButterKnife) NonNull(androidx.annotation.NonNull) TabLayoutMediator(com.test.banner.util.TabLayoutMediator) CircleIndicator(com.youth.banner.indicator.CircleIndicator) ViewPager2(androidx.viewpager2.widget.ViewPager2) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) FragmentStateAdapter(androidx.viewpager2.adapter.FragmentStateAdapter) BindView(butterknife.BindView) DataBean(com.test.banner.bean.DataBean) Fragment(androidx.fragment.app.Fragment) Banner(com.youth.banner.Banner) ImageAdapter(com.test.banner.adapter.ImageAdapter) ImageAdapter(com.test.banner.adapter.ImageAdapter) NonNull(androidx.annotation.NonNull) CircleIndicator(com.youth.banner.indicator.CircleIndicator) TabLayoutMediator(com.test.banner.util.TabLayoutMediator) FragmentStateAdapter(androidx.viewpager2.adapter.FragmentStateAdapter) Fragment(androidx.fragment.app.Fragment)

Example 2 with CircleIndicator

use of com.youth.banner.indicator.CircleIndicator in project banner by youth5201314.

the class GalleryActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gallery);
    ButterKnife.bind(this);
    /**
     * 画廊效果
     */
    mBanner1.setAdapter(new ImageAdapter(DataBean.getTestData2()));
    mBanner1.setIndicator(new CircleIndicator(this));
    // 添加画廊效果
    mBanner1.setBannerGalleryEffect(50, 10);
    // (可以和其他PageTransformer组合使用,比如AlphaPageTransformer,注意但和其他带有缩放的PageTransformer会显示冲突)
    // 添加透明效果(画廊配合透明效果更棒)
    // mBanner1.addPageTransformer(new AlphaPageTransformer());
    /**
     * 魅族效果
     */
    mBanner2.setAdapter(new ImageAdapter(DataBean.getTestData()));
    mBanner2.setIndicator(indicator, false);
    // 添加魅族效果
    mBanner2.setBannerGalleryMZ(20);
}
Also used : ImageAdapter(com.test.banner.adapter.ImageAdapter) CircleIndicator(com.youth.banner.indicator.CircleIndicator)

Example 3 with CircleIndicator

use of com.youth.banner.indicator.CircleIndicator in project banner by youth5201314.

the class TVActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_t_v);
    ButterKnife.bind(this);
    banner.setAdapter(new ImageAdapter(DataBean.getTestData()));
    banner.setIndicator(new CircleIndicator(this));
    banner.isAutoLoop(false);
}
Also used : ImageAdapter(com.test.banner.adapter.ImageAdapter) CircleIndicator(com.youth.banner.indicator.CircleIndicator)

Example 4 with CircleIndicator

use of com.youth.banner.indicator.CircleIndicator 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 5 with CircleIndicator

use of com.youth.banner.indicator.CircleIndicator in project banner by youth5201314.

the class BlankFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    LinearLayout linearLayout = getView().findViewById(R.id.ll_view);
    // 通过new的方式创建banner
    Banner banner = new Banner(getActivity());
    banner.setAdapter(new ImageNetAdapter(DataBean.getTestData3()));
    banner.addBannerLifecycleObserver(this);
    banner.setIndicator(new CircleIndicator(getActivity()));
    // 将banner加入到父容器中,实际使用不一定一样
    linearLayout.addView(banner, LinearLayout.LayoutParams.MATCH_PARENT, (int) BannerUtils.dp2px(120));
}
Also used : Banner(com.youth.banner.Banner) CircleIndicator(com.youth.banner.indicator.CircleIndicator) ImageNetAdapter(com.test.banner.adapter.ImageNetAdapter) LinearLayout(android.widget.LinearLayout)

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