XBanner

项目地址: XBanner

简介:功能强大的图片无限自动轮播控件,可支持自定义状态点及指示器显示位置等功能

支持图片无限轮播的控件,可进行自定义功能。

主要功能:

  • 支持根据服务端返回的数据动态设置广告条的总页数
  • 支持大于等于 1 页时的无限循环自动轮播、手指按下暂停轮播、抬起手指开始轮播
  • 支持自定义状态指示点位置 左 、中 、右
  • 支持自定义状态指示点
  • 支持监听 item 点击事件
  • 支持设置图片轮播间隔
  • 支持指示器背景的修改及隐藏/显示

效果图

1

基本使用

1.添加 Gradle 依赖
dependencies {
    compile 'com.xhb:xbanner:1.0.0'
}
2.在布局文件中添加 XBanner
    <com.stx.xhb.xbanner.XBanner
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/banner_1"
        android:layout_width="match_parent"
        android:layout_height="180dp"
        app:pointsPosition="CENTER"
        app:AutoPlayTime="3000"
        app:pointsContainerBackground="#44aaaaaa"
        app:pointNormal="@drawable/shape_noraml"
        app:pointSelect="@drawable/shape_selected"/>
3.在 Activity 或者 Fragment 中配置

初始化:直接传入视图集合进行初始化

        imgesUrl = new ArrayList<>();
        imgesUrl.add("http://img3.fengniao.com/forum/attachpics/913/114/36502745.jpg");
        imgesUrl.add("http://imageprocess.yitos.net/images/public/20160910/99381473502384338.jpg");
        imgesUrl.add("http://imageprocess.yitos.net/images/public/20160910/77991473496077677.jpg");
        imgesUrl.add("http://imageprocess.yitos.net/images/public/20160906/1291473163104906.jpg");
        mBannerNet.setData(imgesUrl);
4.加载广告

可根据自己项目需要使用相应的图片加载工具进行加载图片,此处使用 Glide,进行加载,可配置占位图等

 mBannerNet.setmAdapter(this);
 @Override
    public void loadBanner(XBanner banner, View view, int position) {
        Glide.with(this).load(imgesUrl.get(position)).into((ImageView) view);
    }
5.监听广告 item 的单击事件
 mBannerNet.setOnItemClickListener(new XBanner.OnItemClickListener() {
            @Override
            public void onItemClick(XBanner banner, int position) {
                Toast.makeText(MainActivity.this, "点击了第"+position+"图片", Toast.LENGTH_SHORT).show();
            }
        });

自定义属性说明

属性名属性说明属性值
isAutoPlay是否支持自动轮播boolean 类型,默认为 true
AutoPlayTime图片轮播时间间隔int 值,默认为 5s
pointNormal指示器未选中时状态点drawable,不设置的话为默认状态点
pointSelect指示器选中时状态点drawable,不设置的话为默认状态点
pointsVisibility是否显示指示器boolean 类型,默认为 true
pointsPosition指示点显示位置LEFT、CENTER、RIGHT 类型,默认为 CENTER
pointsContainerBackground指示器背景可自定义设置指示器背景

关于我

个人邮箱:xhb_199409@163.com

GitHub 主页

简书主页

个人博客

License

Copyright (C) 2016 xhb_199409@163.com

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值