实现效果如下:

使用方法:

在layout文件中添加以下代码:

   <com.example.jack.ui.widget.RingLoading
android:layout_width="20.0dip"
android:layout_height="20.0dip"
/>

具体代码如下:

package com.example.jack.ui.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.SweepGradient;
import android.util.AttributeSet;
import android.view.View; /**
* Created by pengf on 2017/4/10.
*/ public class RingLoading extends View
{
private static final int PROGRESS = 5;
private int centerX;
private int centerY;
private Context context;
private int mProgressColor ;
private Matrix matrix;
private final Paint paint;
private int roundWidth = 10;
private int start = 0; public RingLoading(Context context, AttributeSet attrs)
{
super(context, attrs);
this.context = context;
this.paint = new Paint();
this.paint.setAntiAlias(true);
this.paint.setStyle(Paint.Style.STROKE);
this.paint.setStrokeWidth(this.roundWidth);
this.mProgressColor =Color.parseColor("#ffffcc00"); } @Override
protected void onDraw(Canvas canvas)
{
int center = getWidth() / 2;
int radius = center - this.roundWidth / 2;
SweepGradient sweepGradient = new SweepGradient(this.centerX, this.centerY, Color.TRANSPARENT, this.mProgressColor);
this.paint.setShader(sweepGradient);
this.matrix = new Matrix();
this.matrix.postRotate(this.start, this.centerX, this.centerY);
canvas.concat(this.matrix);
canvas.drawCircle(center, center, radius, this.paint);
this.start = (PROGRESS + this.start);
invalidate();
} @Override
protected void onSizeChanged(int w, int h, int oldw, int oldh)
{
super.onSizeChanged(w, h, oldw, oldh);
this.centerX = (w / 2);
this.centerY = (h / 2);
}
}

一个简单的Loading控件的更多相关文章

  1. 【VS开发】 自己编写一个简单的ActiveX控件——详尽教程

    最近开始学ActiveX控件编程,上手不太容易,上网想找相关教程也没合适的,最后还是在师哥的指导下完成了第一个简单控件的开发,现在把开发过程贴出来与大家分享一下~ (环境说明--平台:vs2005:语 ...

  2. 调用ocx ActiveX控件详解(做一个简单的ocx控件)

    背景 最近做的项目都和插件有关,就是在页面中调用插件的方法,然后进行操作. 插件就是ocx ActiveX控件,具体的说明可以自己去了解一下,在这里就不做赘述. 具体调用方式很简单: 1.在页面中写一 ...

  3. 在iOS上实现一个简单的日历控件

    http://blog.csdn.net/jasonblog/article/details/21977481 近期需要写一个交互有点DT的日历控件,具体交互细节这里略过不表. 不过再怎么复杂的控件, ...

  4. 怎样在Android实现桌面清理内存简单Widget小控件

    怎样在Android实现桌面清理内存简单Widget小控件 我们常常会看到类似于360.金山手机卫士一类的软件会带一个widget小控件,显示在桌面上,上面会显示现有内存大小,然后会带一个按键功能来一 ...

  5. WPF实现炫酷Loading控件

    Win8系统的Loading效果还是很不错的,网上也有人用CSS3等技术实现,研究了一下,并打算用WPF自定义一个Loading控件实现类似的效果,并可以让用户对Loading的颗粒(Particle ...

  6. 一个动态扩展表格控件列和行的 jQuery 插件

    一个动态扩展表格控件列和行的 jQuery 插件 不过这并不影响使用鸭! 看这里:https://github.com/zhuwansu/table-ext.js 一个简单的示范 html <t ...

  7. 分享一个漂亮的ProgressBar控件

    codeprject上看到的一个漂亮的ProgressBar控件.是用vb.net开发的. C#直接在工具箱中引用即可. 地址:http://www.codeproject.com/Articles/ ...

  8. Aspose是一个很强大的控件,可以用来操作word,excel,ppt等文件

    Aspose是一个很强大的控件,可以用来操作word,excel,ppt等文件,用这个控件来导入.导出数据非常方便.其中Aspose.Cells就是用来操作Excel的,功能有很多.我所用的是最基本的 ...

  9. android开发中一个activity如何调用另一个xml中的控件

    有时候,我们需要在一个activity中使用另一个activity中的控件,这时候就不能直接findViewById,不然会报错指向空对象,这时就需要像下面这样做. LayoutInflater fa ...

随机推荐

  1. SpringBoot系列: Eclipse+Maven环境准备

    这个链接比我写得更全面, http://tengj.top/2018/01/01/maven/ =============================20190115补充: maven 的一些插件 ...

  2. Android获取版本号

    public static String getVersionName(Context context) { PackageManager manager = context.getPackageMa ...

  3. idea 2018.1破解激活方法,有效期至2099年

    优点:有效期至2099年,不出意外,这辈子肯定够用了 缺点:稍微麻烦些,不过不要紧,为了以后省事,都值了 下面是具体的破解激活步骤: 1. 下载破解补丁文件,路径为:http://idea.lanyu ...

  4. 【LDAP】LDAP注入漏洞与防御

    0x01 前言 前两天爆了一个LDAP漏洞,据说存在了8年现在才被发现,感概一下,不知这8年来有多少站被搞了... 想着复现这个漏洞,就先复习一下LDAP注入的相关知识吧,差了很多资料,记一下笔记. ...

  5. ads出现村田电容电感无法仿真的问题解决(`BJT1' is an instance of an undefined model `BJTM1')

    需要的控件是 murata include,该控件是跟随村田库一起倒入ADS中的

  6. webstorm更改scss输出路径

    --no-cache --update $FileName$:$FileParentDir$\css\$FileNameWithoutExtension$.css $FileNameWithoutEx ...

  7. Serializable 和Parcelable 的区别

    1.作用 Serializable的作用是为了保存对象的属性到本地文件.数据库.网络流.RMI(Remote Method Invocation)以方便数据传输,当然这种传输可以是程序内的也可以是两个 ...

  8. invalidate和requestLayout

    Invalidate:To farce a view to draw,call invalidate().——摘自View类源码从上面这句话看出,invalidate方法会执行draw过程,重绘Vie ...

  9. shell编程 之 test命令

    shell编程里的测试test命令基本可以分为3种数据类型,每种都不一样.个人更倾向于理解为条件语句的写法规则,就是test加条件加判断语句. 1 数值类型 基本可以分为6个判断:-eq等于,-ne不 ...

  10. Intel Xeon E5-2620 v4参数

    基本参数 CPU系列 Xeon E5 v4系列 制作工艺 14纳米 核心代号 Broadwell 性能参数 核心数量 八核心 线程数量 十六线程 CPU主频 2.1GHz 动态加速频率 3GHz L3 ...