XBanner

    xiaoxiao2022-06-30  59

    项目地址: XBanner

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

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

    主要功能:

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

    效果图

    基本使用

    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 类型,默认为 trueAutoPlayTime图片轮播时间间隔int 值,默认为 5spointNormal指示器未选中时状态点drawable,不设置的话为默认状态点pointSelect指示器选中时状态点drawable,不设置的话为默认状态点pointsVisibility是否显示指示器boolean 类型,默认为 truepointsPosition指示点显示位置LEFT、CENTER、RIGHT 类型,默认为 CENTERpointsContainerBackground指示器背景可自定义设置指示器背景

    关于我

    个人邮箱: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.
    转载请注明原文地址: https://ju.6miu.com/read-1125811.html

    最新回复(0)