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'
}
0
投稿
猜你喜欢
- 1.准备工作第一步就是先要注册一个支付宝的账号(注册这里不说,不是重点),然后登入官方首页,去到应用列表里面找到沙箱应用。基本信息的APPI
- 前言春节要到了,看惯了前端各种小游戏,确实做得很好,很精致。但是我也要为后端程序员稍微做一点贡献,做一款java版本的【年兽大作战】。这个游
- 温馨提示:本教程的 GitHub 地址为「intellij-idea-tutorial」,欢迎感兴趣的童鞋Star、Fork,纠错。首先,给
- SpringBoot @ConditionalOnBean实现原理在SpringBoot1.5.X时判断条件是OR,SpringBoot2.
- 绝对路径:不可改变的路径本地绝对路径:增加盘符的路径(e:/test/test.html)网络绝对路径:增加协议,IP地址,端口号的路径(h
- 一、 * 与过滤器在讲Spring boot之前,我们先了解一下过滤器和 * 。这两者在功能方面很类似,但是在具体技术实现方面,差距还是比较
- Spring Data JPA查询方式及方法名查询规则Spring Data JPA通过解析方法名创建查询在执行查询时,Spring Dat
- 该接口实现了序列化,声明为 public interface Key extends SerializableKey 是所有密钥的顶层接口。
- # 前言之前在学习C语言的时候,做过一个三子棋的小游戏,最近开始学习Java,就想着能不能用Java再把之前的练习重新实现一边,既然有这个想
- 之前我们借助一个SuperSocket实现了一个简易版的服务器, 但是不管是Server还是Session都是使用框架的,本篇博客我们要实现
- 本文实例为大家分享了Java Socket实现多人聊天系统的具体代码,供大家参考,具体内容如下前言GitHub地址开发环境:Eclipse
- SpringMVC中事务是否可以加在Controller层一般而言,事务都是加在Service层的,但是爱钻牛角尖的我时常想:事务加在Con
- strftime函数主要用于时间格式化,它的函数原型如下:size_t __cdecl strftime(char * __restrict
- 记录一下使用IDEA创建servlet并使用Tomcat本地部署的过程。需要安装好的软件首先IDEA社区版不支持Java EE,因此要使用U
- 首先微信公众号开发网页授权登录使用环境:开发工具:eclipse;服务器:tomcat8,开发语言:JAVA。我写的网页授权登录时用开发者模
- java url中如何传递数组,springMVC框架controller类如何接收数组参数?下面介绍一下URL中传递数组参数方法:dd.d
- 第一次写技术博客,写一下以前写的一个双色球抽奖随机算法。原理如下:1首先初始化一个待抽奖的数组nums,数组的长度k2. 随机一个1-k之间
- C#中的null与SQL中的NULL是不一样的,SQL中的NULL用C#表示出来就是DBNull.Value。注意:SQL参数是不能接受C#
- 一、支持的数据类型Flink 对可以在 DataSet 或 DataStream 中的元素类型进行了一些限制。这样做的原因是系统会分析类型以
- Java API不能远程访问HBase今天我在虚拟机里面安装了Hbase 1.2.4,说在windows上Java API调用访问下玩玩,结