Android自定义封装banner组件

所属分类: 软件编程 / Android 阅读数: 29
收藏 0 赞 0 分享

自定义封装 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'
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

更多精彩内容其他人还在看

Android中加入名片扫描功能实例代码

这篇文章主要介绍了Android中加入名片扫描功能实例代码的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享

Android仿微信发表说说实现拍照、多图上传功能

这篇文章主要为大家详细介绍了Android仿微信发表说说实现拍照、多图上传功能,使用Retrofit2.0技术,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

设置Android系统永不锁屏永不休眠的方法

在进行Android系统开发的时候,有些特定的情况需要设置系统永不锁屏,永不休眠。本篇文章给大家介绍Android 永不锁屏,开机不锁屏,删除设置中休眠时间选项,需要的朋友一起学习吧
收藏 0 赞 0 分享

Android Retrofit 2.0框架上传图片解决方案

这篇文章主要介绍了Android Retrofit 2.0框架上传一张与多张图片解决方案,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

Android自定义等待对话框

这篇文章主要为大家详细介绍了Android自定义等待对话框的实现方法,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

Android中Window添加View的底层原理

这篇文章主要介绍了Android中Window添加View的底层原理,需要的朋友可以参考下
收藏 0 赞 0 分享

Android调用系统默认浏览器访问的方法

这篇文章主要介绍了Android调用系统默认浏览器访问的方法的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享

Android开发退出程序的方法汇总

Android程序有很多Activity,比如说主窗口A,调用了子窗口B,子窗口B又调用子窗口C,back返回子窗口B后,在B中如何关闭整个Android应用程序呢? 下面脚本之家小编就给大家介绍android开发退出程序的几种方法,感兴趣的朋友参考下吧
收藏 0 赞 0 分享

Android程序开发中单选按钮(RadioGroup)的使用详解

在android程序开发中,无论是单选按钮还是多选按钮都非常的常见,接下来通过本文给大家介绍Android程序开发中单选按钮(RadioGroup)的使用,需要的朋友参考下吧
收藏 0 赞 0 分享

Android实现仿网易今日头条等自定义频道listview 或者grideview等item上移到另一个view中

这篇文章主要介绍了Android实现仿网易今日头条等自定义频道listview 或者grideview等item上移到另一个view中 的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多