Android 自定义 View 之 LeavesLoading

作者: androidproject 发布时间: 2019-09-05 浏览: 2205 次 编辑

LeavesLoading 

1. 创意原型

Gif 原图:

效果图:

基本实现了原图的效果

2. 如何添加进项目中

仓库:

  • 方式一:

    下载 LeavesLoading Library 拷贝进工程中。

    tip: 不是当前的 TestLeavesLoading 项目哦!

  • 方式二:

    在 project 的 build.gradle 中:

    allprojects {
      	repositories {  		...
      		maven { url 'https://jitpack.io' }
      	}
      }

    在 app 的 build.gradle 中:

     implementation 'com.github.LinYaoTian:LeavesLoading:1.0.2'

3. 如何使用

3.1 简单使用

在布局文件中

 <com.rdc.leavesloading.LeavesLoading           
              android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/myleaf"/>

在 Activity 中

LeavesLoading leavesLoading = findViewById(R.id.myleaf);
leavesLoading.setProgress(50);

3.2 方法

方法名描述
setLeafSrc(int resId)设置叶子图片
setFanSrc(int resId)设置风扇图片
setProgress(int progress)设置进度
setProgressColor(int color)设置进度条颜色
setLeafNum(int num)设置叶片数目
setLeafFloatTime(long time)设置叶子飘动一个周期所花时间
setLeafRotateTime(long time)设置叶子旋转一周所花时间
setFanRotateSpeed(int speed)设置风扇旋转速度
setFanStroke(int color)设置风扇外圈颜色
setBgColor(int color)设置背景颜色

3.3 Attributes属性(在布局文件中调用)

Attributesformadescribe
leafSrcreference叶子图片
leafNuminteger叶子数目
fanSrcreference风扇图片
bgColorcolor背景颜色
progressinteger进度值(0-100)
progressColorcolor进度条颜色
leafFloatSpeedinteger叶子飘动一个周期所花时间
leafRotateSpeedinteger叶子旋转一周所花时间
fanRotateSpeedinteger设置风扇旋转速度
fanStrokeColorcolor风扇外圈颜色

4. About Me

作者掘金博客:Lin_YT

项目地址:https://github.com/LinYaoTian/TestLeavesLoading