Android 自定义View 三 圆环交替 等待效果

本文分享了如何使用自定义View来实现圆环交替等待效果,包括关键属性如颜色、速度和圆环宽度的设置,并提供了源码下载。同时介绍了Markdown编辑器的新功能,如图片拖拽、代码高亮、甘特图和流程图等。
摘要由CSDN通过智能技术生成

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/24500107

一个朋友今天有这么个需求(下图),我觉得那自定义View来做还是很适合的,就做了下,顺便和大家分享下,对于自定义View多练没坏处么。如果你看了前两篇,那么这篇一定so easy 。


效果就这样,分析了一下,大概有这几个属性,两个颜色,一个速度,一个圆环的宽度。

还是我们自定View的那几个步骤:

1、自定义View的属性

2、在View的构造方法中获得我们自定义的属性

[ 3、重写onMesure ]

4、重写onDraw

-------------------------------------------------------------------------------------------------------------------

1、自定义属性:

<?xml version="1.0" encoding="utf-8"?><resources>    <attr name="firstColor" format="color" />    <attr name="secondColor" format="color" />    <attr name="circleWidth" format="dimension" />    <attr name="speed" format="integer" />    <declare-styleable name="CustomProgressBar">        <attr name="firstColor" />        <attr name="secondColor" />        <attr name="circleWidth" />        <attr name="speed" />    </declare-styleable></resources>

2、 在View的构造方法中获得我们自定义的属性

/**  * 第一圈的颜色  */ private int mFirstColor; /**  * 第二圈的颜色  */ private int mSecondColor; /**  * 圈的宽度  */ private int mCircleWidth; /**  * 画笔  */ private Paint mPaint; /**  * 当前进度  */ private int mProgress; /**  * 速度  */ private int mSpeed; /**  * 是否应该开始下一个  */ private boolean isNext = falsepublic CustomProgressBar(Context context, AttributeSet attrs) {  this(context, attrs, 0); } public CustomProgressBar(Context context) {  this(context, null); } /**  * 必要的初始化,获得一些自定义的值  *   * @param context  * @param attrs  * @param defStyle  */ public CustomProgressBar(Context context, AttributeSet attrs, int defStyle) {  super(context, attrs, defStyle);  TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CustomProgressBar, defStyle, 0);  int n = a.getIndexCount();  for (int i = 0; i < n; i++)  {   int attr = a.getIndex(i);   switch (attr)   {   case R.styleable.CustomProgressBar_firstColor:    mFirstColor = a.getColor(attr, Color.GREEN);    break;   case R.styleable.CustomProgressBar_secondColor:    mSecondColor = a.getColor(attr, Color.RED);    break;   case R.styleable.CustomProgressBar_circleWidth:    mCircleWidth = a.getDimensionPixelSize(attr, (int) TypedValue.applyDimension(      TypedValue.COMPLEX_UNIT_PX, 20, getResources().getDisplayMetrics()));    break;   case R.styleable.CustomProgressBar_speed:    mSpeed = a.getInt(attr, 20);// 默认20    break;   }  }  a.recycle();  mPaint = new Paint();  // 绘图线程  new Thread()  {   public void run()   {    while (true)    {     mProgress++;     if (mProgress == 360)     {      mProgress = 0;      if (!isNext) 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值