美文网首页
Banner轮播

Banner轮播

作者: MissmoBaby | 来源:发表于2017-07-06 09:58 被阅读0次

组件介绍

这个组件用于android项目中,实现图片轮播的效果,并有对应的指示器。

动态图

banner.gif

使用场景

这个组件可以用于轮播,也可以用于其他的页面切换。轮播功能也可以关闭,并不只是能加载图片,也可以加载其他的控件或布局,如Fragment、混合布局等。下面的指示器也可以自定义使用。

如何使用

第一步:xml布局

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/framelayout"
    android:layout_width="fill_parent"
    android:layout_height="150dp"
    android:orientation="vertical">
    <com.qr.item.widget.banner.viewflow.ViewFlow
        android:id="@+id/mainhome_fragment_viewflow"
        android:layout_width="match_parent"
        android:layout_height="150dp"/>
    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="#00000000"
        android:gravity="center"
        android:padding="3dip">
        <com.qr.item.widget.banner.viewflow.CircleFlowIndicator
            android:id="@+id/mainhome_fragment_viewflowindic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal|bottom"
            android:layout_marginBottom="2dp"
            android:paddingLeft="3dp"
            android:paddingTop="2dp"
            android:visibility="gone"
            app:activeColor="#ffffff"
            app:activeType="fill"
            app:circleSeparation="20dp"
            app:inactiveColor="#55ffffff"
            app:inactiveType="fill"
            app:radius="4dp"/>
    </FrameLayout>
    <ImageView
        android:id="@+id/bannerImg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY" />
</FrameLayout>

第二步:初始化控件

mViewFlow = (ViewFlow) findViewById(R.id.mainhome_fragment_viewflow);
mFlowIndicator = (CircleFlowIndicator) findViewById(R.id.mainhome_fragment_viewflowindic);

第三步:加载数据源

private ArrayList<String> imageUrlList = new ArrayList<String>();// Banner的图片
private ArrayList<String> linkUrlArray = new ArrayList<String>();// Banner所对应的连接
private ArrayList<String> titlelist = new ArrayList<String>();// Banner所对应的标题

第四步:设置适配器

private BannerAdapter setInfiniteLoop;
setInfiniteLoop = new BannerAdapter(this, R.mipmap.banner,imageUrlList, linkUrlArray, titlelist).setInfiniteLoop(true);
setInfiniteLoop.setOnShowBannerListener(new WidgetInterface.OnShowBannerListener() {
            @Override
            public void show(int position, ImageView imageView, String imgUrl) {
                Glide.with(BannerActivity.this).load(imgUrl).placeholder(R.mipmap.banner).error(R.mipmap.banner).into(imageView);
            }
        });

第五步:功能配置

mViewFlow.setAdapter(setInfiniteLoop);
mViewFlow.setmSideBuffer(imageUrlList.size()); // 实际图片张数,
mViewFlow.setFlowIndicator(mFlowIndicator);
mViewFlow.setTimeSpan(3000);
mViewFlow.setSelection(imageUrlList.size() * 1000); // 设置初始位置
mViewFlow.startAutoFlowTimer(); // 启动自动播放
mViewFlow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            }
        });```

###注意事项
>第三步中setOnShowBannerListener必须紧接着new BannerAdapter()设置,setOnShowBannerListener为图片设置回调方法。

###版本控制
| 版本号  |  更新内容 | 修改人  | 修改时间 | 
| :-------  | :-------: | :-------: |  -------: | 
|       1.0 |初次发布     | lucky_bear       |  2017/7/6    | 

###项目地址
| 所在文件夹 |  demo位置|
| :-------  | :-------: |
|       widget.Banner |com.qr.demo.widget.BannerActivity|

相关文章

  • banner轮播图

    banner轮播 *{ margin: 0;...

  • Banner实现方法及其命令

    设置banner轮播加文字 4.Attributes属性(banner布局文件中调用)

  • 封装

    Button: Banner轮播(CollectionView): Button Section: Button ...

  • Banner

    利用** ViewPager **实现广告 Banner 循环轮播。

  • app首页 Banner轮播图取色,背景和状态栏颜色渐变

    app首页 Banner轮播图取色,背景和状态栏颜色渐变目前购物推荐banner轮播和读书、听书类等App都会有此...

  • Android实现轮播

    先上一个实现图 依赖: 轮播依赖: implementation'com.youth.banner:banner:...

  • Banner轮播

    京东快报轮播公告的实现 ViewPagerIndicator

  • Banner轮播

    组件介绍 这个组件用于android项目中,实现图片轮播的效果,并有对应的指示器。 动态图 使用场景 这个组件可以...

  • banner轮播

    图片轮播可以说时最常用的效果之一了。实现起来算是比较简单,当然没有前端那么简单。这里让我大声赞美一声swiper,...

  • 页面常用标签

    header 头部 nav 导航 banner 轮播 search 搜索 main ...

网友评论

      本文标题:Banner轮播

      本文链接:https://www.haomeiwen.com/subject/cxqicxtx.html