Android自定义封 * anner组件
作者:丁小雨™ 发布时间:2023-08-25 22:19:29
标签:Android,banner,组件
自定义封装 banner 组件,供大家参考,具体内容如下
1. 效果图预览
2.基本功能
一个简单方便的轮播图组件,基于viewpager 基础上进行的封装。
可设置 项目中图片,网络图片, View;
支持循环自动播放,手势滑动切换,item点击事件,可设置 点点的样式宽高、颜色、大小、位置 ;
可设置蒙层;可设置 是否允许滑动;可设置 是否允许循环。
3.基本实现
1). 自定义属性
<declare-styleable name="BannerLayoutStyle">
<attr name="maskStartColor" format="color|reference" />
<attr name="maskEndColor" format="color|reference" />
<attr name="selectedIndicatorColor" format="color|reference" />
<attr name="unSelectedIndicatorColor" format="color|reference" />
<attr name="indicatorShape" format="enum">
<enum name="rect" value="0" />
<enum name="oval" value="1" />
</attr>
<attr name="selectedIndicatorHeight" format="dimension|reference" />
<attr name="selectedIndicatorWidth" format="dimension|reference" />
<attr name="unSelectedIndicatorHeight" format="dimension|reference" />
<attr name="unSelectedIndicatorWidth" format="dimension|reference" />
<attr name="indicatorPosition" format="enum">
<enum name="centerBottom" value="0" />
<enum name="rightBottom" value="1" />
<enum name="leftBottom" value="2" />
<enum name="centerTop" value="3" />
<enum name="rightTop" value="4" />
<enum name="leftTop" value="5" />
</attr>
<attr name="indicatorSpace" format="dimension|reference" />
<attr name="indicatorMargin" format="dimension|reference" />
<attr name="autoPlayDuration" format="integer|reference" />
<attr name="scrollDuration" format="integer|reference" />
<attr name="isAutoPlay" format="boolean" />
<attr name="defaultImage" format="integer|reference" />
<attr name="isIndicatorVisible" format="boolean" />
<attr name="cornerRadii" format="dimension|reference" />
</declare-styleable>
2).基本方法
//添加本地图片路径
public void setViewRes(List<Integer> viewRes) {。。。}
//添加网络图片路径
public void setViewUrls(List<String> urls) {。。。}
//添加任意View视图
private void setViews2(final List<View> views) {。。。}
// 设置是否允许 循环
public void setLoop(boolean loop) {
}
// 设置是否可以滑动
public void setSlideable(boolean slideable) {
}
更多用法 详见代码,这里就不全部粘贴了。
3).使用示例:
<com.dzq.widget.CustomBannerView
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
app:autoPlayDuration="2000"
app:defaultImage="@drawable/bg_banner"
app:indicatorMargin="@dimen/indicatorMargin"
app:indicatorPosition="rightBottom"
app:indicatorShape="oval"
app:indicatorSpace="@dimen/indicatorSpace"
app:isAutoPlay="true"
app:isIndicatorVisible="true"
app:scrollDuration="1000"
app:selectedIndicatorColor="@color/color_ec407a"
app:selectedIndicatorHeight="5dp"
app:selectedIndicatorWidth="5dp"
app:unSelectedIndicatorColor="@color/color_71d9e7"
app:unSelectedIndicatorHeight="5dp"
app:unSelectedIndicatorWidth="5dp"
/>
<com.dzq.widget.CustomBannerView
android:id="@+id/banner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="1"
app:autoPlayDuration="2000"
app:defaultImage="@drawable/bg_banner"
app:indicatorMargin="@dimen/indicatorMargin"
app:indicatorPosition="rightBottom"
app:indicatorShape="rect"
app:indicatorSpace="@dimen/indicatorSpace"
app:isAutoPlay="false"
app:isIndicatorVisible="true"
app:scrollDuration="1000"
app:selectedIndicatorColor="@color/color_ec407a"
app:selectedIndicatorHeight="5dp"
app:selectedIndicatorWidth="10dp"
app:unSelectedIndicatorColor="@color/color_71d9e7"
app:unSelectedIndicatorHeight="10dp"
app:unSelectedIndicatorWidth="5dp"
/>
<com.dzq.widget.CustomBannerView
android:id="@+id/banner3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="1"
app:cornerRadii="5dp"
app:indicatorMargin="@dimen/indicatorMargin"
app:indicatorPosition="centerTop"
app:indicatorShape="rect"
app:indicatorSpace="@dimen/indicatorSpace"
app:isAutoPlay="false"
app:isIndicatorVisible="true"
app:maskEndColor="#00000000"
app:maskStartColor="#99000000"
app:scrollDuration="1000"
app:selectedIndicatorColor="#00CAA9"
app:selectedIndicatorHeight="10dp"
app:selectedIndicatorWidth="25dp"
app:unSelectedIndicatorColor="#26000000"
app:unSelectedIndicatorHeight="10dp"
app:unSelectedIndicatorWidth="10dp" />
项目源码下载
导入自己项目
How to
To get a Git project into your build:
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.dingzuoqiang:CustomBannerView:v1.0'
}


猜你喜欢
- 很多核心 Java 面试题来源于多线程(Multi-Threading)和集合框架(Collections Framework),理解核心线
- 我们肯定遇到过打开别人的项目时一直处于Building‘XXX'Gradle project info的情况。本文通过两种方法带领大
- Room在SQLite基础上做了ORM封装,使用起来类似JPA,不需要写太多的sql。导入依赖//roomdef room_version=
- 这里记录Java中从控制台读入信息的几种方式,已备后查!(1)JDK 1.4(JDK 1.5和JDK 1.6也都兼容这种方法)public
- 前言《接月饼小游戏》是一个基于java的自制游戏,不要被月亮砸到,尽可能地多接月饼。此小项目可用来巩固JAVA基础语法,swing的技巧用法
- 懒加载---就是我们在spring容器启动的是先不把所有的bean都加载到spring的容器中去,而是在当需要用的时候,才把这个对象实例化到
- 本文实例讲述了Android编程绘图操作之弧形绘制方法。分享给大家供大家参考,具体如下:/** * 绘制弧形图案 * @descriptio
- 当我们需要与 NIO Channel 进行交互时, 我们就需要使用到 NIO Buffer, 即数据从 Buffer读取到 Channel
- 前言本文主要给大家介绍了关于Spring Boot应用极速部署脚本的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧
- 目录前言一、技术介绍1.ReentranReadWriteLock是什么?二、源码分析1.ReadLock2.WriteLock三、单元测试
- 本文实例为大家分享了ftp实现文件上传下载的具体代码,供大家参考,具体内容如下package getUrlPic;import java.i
- 1 pom.xml文件注:热部署功能spring-boot-1.3开始有的<!--添加依赖--><dependency&g
- 在程序中,进行类型转换是常见的事,C#支持基本的强制类型转换方法,例如:Object obj1 = new NewType();NewTyp
- rabbitMQ是一个在AMQP协议标准基础上完整的,可服用的企业消息系统。它遵循Mozilla Public License开源协议,采用
- 1.使用keySet进行遍历实现步骤:(1)使用Map集合中的方法keySet(),把Map集合所有的key取出来,存储到一个Set集合中(
- 一、安装插件1.1直接用离线安装,将安装包拖到 IDEA窗口就安装好了,需要重启IDEA生效 (推荐)1.2 直接在idea上下JFormD
- 本文所述为一个C#使用iCSharpcode压缩的使用类,经测试效果不错。分享给大家供大家参考之用。具体方法如下:1.参数类using Sy
- 简要DecimalFormat 的 pattern 都包含着 正负子 pattern ,例如 “#,##0.00;(#,##0.00)”:/
- 一、简介现在的Android应用程序中,不可避免的都会使用到图片,如果每次加载图片的时候都要从网络重新拉取,这样不但很耗费用户的流量,而且图
- spring开启声明式事务导入依赖pom.xml<dependencies>