Home

Awesome

YCBanner轮播图

目录介绍

1.功能说明

1.1 基础功能介绍

1.2 该库的优势

2.ViewPager轮播图使用说明

<com.yc.cn.ycbannerlib.BannerView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/banner"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    app:hint_color="@color/colorAccent"
    app:hint_gravity="center"
    app:hint_mode="point"
    app:play_delay="2000"/>
private void initBanner() {
    banner = (BannerView) findViewById(R.id.banner);
    //设置轮播时间
    banner.setPlayDelay(2000);
    //设置轮播图适配器,必须
    banner.setAdapter(new ImageNormalAdapter());
    //设置位置
    banner.setHintGravity(1);
    //设置指示器样式
    banner.setHintMode(BannerView.HintMode.TEXT_HINT);
    //判断轮播是否进行
    boolean playing = banner.isPlaying();
    //轮播图点击事件
    banner.setOnBannerClickListener(new OnBannerClickListener() {
        @Override
        public void onItemClick(int position) {
            Toast.makeText(FirstActivity.this,position+"被点击呢",Toast.LENGTH_SHORT).show();
        }
    });
    //轮播图滑动事件
    banner.setOnPageListener(new OnPageListener() {
        @Override
        public void onPageChange(int position) {

        }
    });
}


private class ImageNormalAdapter extends AbsStaticPagerAdapter {

    @Override
    public View getView(ViewGroup container, int position) {
        ImageView view = new ImageView(container.getContext());
        view.setScaleType(ImageView.ScaleType.CENTER_CROP);
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        view.setImageResource(imgs[position]);
        return view;
    }

    @Override
    public int getCount() {
        return imgs.length;
    }
}
@Override
protected void onPause() {
    super.onPause();
    if(banner!=null){
        //停止轮播
        banner.pause();
    }
}

@Override
protected void onResume() {
    super.onResume();
    if(banner!=null){
        //开始轮播
        banner.resume();
    }
}

3.跑马灯使用说明

3.1 在布局中添加代码

<!--上下滚动TextView-->
<com.yc.cn.ycbannerlib.marquee.MarqueeView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/marqueeView"
    android:layout_width="match_parent"
    android:layout_marginTop="10dp"
    android:layout_height="40dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_gravity="center_vertical"
    app:paddingStart="0dp"
    app:mvAnimDuration="1000"
    app:mvInterval="2000"
    app:mvTextColor="#464C4E"
    app:mvTextSize="16sp"
    app:mvSingleLine="true"/>

3.2 使用

List<CharSequence> list = getMarqueeTitle();
//根据公告字符串列表启动轮播
marqueeView.startWithList(list);
//设置点击事件
marqueeView.setOnItemClickListener(new MarqueeView.OnItemClickListener() {
    @Override
    public void onItemClick(int position, TextView textView) {

    }
});

4.RecyclerView轮播图

4.1 RecyclerView轮播图简单使用

<com.yc.gallerybannerlib.GalleryRecyclerView
    android:layout_marginTop="35dp"
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="200dp"/>
private void initRecyclerView() {
    Snap3Adapter adapter = new Snap3Adapter(this);
    adapter.setData(getData());
    mGalleryRecyclerView.setDelayTime(3000)
            .setFlingSpeed(0)
            .setDataAdapter(adapter)
            .setSelectedPosition(100)
            .setCallbackInFling(false)
            .setOnItemSelectedListener(new GalleryRecyclerView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(RecyclerView recyclerView, View item, int position) {
                    Log.e("onItemSelected-----",position+"");
                    //设置高斯模糊背景
                    setBlurImage(true);
                }
            })
            .setSize(adapter.getData().size())
            .setUp();
}

4.2 RecyclerView实现平滑滚动,图片剧中效果

GalleryLayoutManager manager = new GalleryLayoutManager(LinearLayoutManager.HORIZONTAL);
manager.attach(recyclerView,100);
//如果想缩放,可以直接设置缩放比例因子即可
manager.setItemTransformer(new GalleryScaleTransformer( 0.2f));
recyclerView.setLayoutManager(manager);
Snap3Adapter adapter = new Snap3Adapter(this);
adapter.setData(getData());
recyclerView.setAdapter(adapter);

4.3 关于自定义SnapHelper类

5.图片展示

<source id="mp4" src="https://github.com/yangchong211/YCBanner/blob/master/image/4.mp4" type="video/mp4"> </video>

6.其他介绍

5.1版本更新说明

关于其他内容介绍

image

关于博客汇总链接

于LICENSE

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.