Android 自己定義圓圈進度並顯示百分比例控件(純代碼實現)
先不說實現功能,上圖看看效果
這個是續上一次水平變色進度條的有一個全新的控件,理論實現原理
1.分析控件:該控件基本上是圓圈內嵌圓圈;
2.進度計算:事實上是小學二年級數學題:當前進度/總數=百分比;
3.中間時間:呵呵,純粹忽悠,不解釋(當前時間)。理論總是和實踐差距的太遠。不扯淡。不吹噓,貼代碼:
package com.spring.progressview; import java.text.SimpleDateFormat; import java.util.Date; import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Align; import android.graphics.Paint.Style; import android.graphics.Rect; import android.graphics.RectF; import android.util.AttributeSet; import android.view.View; /**** * 圓圈進度控件 * @author spring sky * Email:[email protected]
盡管僅僅有短短不到200行代碼。可是,裏面的有些基本函數。我還是得簡單的說明
1. Color.argb(60, 255, 255, 255); 這個是來得到一個顏色。而且設置他的透明度。第一個參數就是透明度,0~255之間,其它的RGB,呵呵。不解釋,自己搞。
2. 以下的兩個方法,是畫筆的方法。非常重要
mPaint.setStyle(Style.STROKE); //這個是原來顯示空心的東西
mPaint.setStrokeWidth(mProgressWidth); //這個是空心最外層的寬度
比方:drawArc 是畫一個圓,那麽,我們的設置了以上兩個方法,就是要畫一個空心圓,圓的軌跡寬度就是 mProgressWidth
3.畫圓的時候,開始度數和結束度數一定要控制好哦。
4.假設您還有什麽不懂的,請多了解:Canvas 和Paint的相關方法和API,在此不勝感激。
寫這篇博客的目的為了分享,我也希望能給你們提供一些思路,希望大家把不錯的控件都共享出來,不勝感激。
好了。博客貼出去,肯定有非常多人要Demo,為了防止蜘蛛亂抓取而丟失下載地址。地址請看代碼上的註明點。
轉載請註明作者來源:
Android 自己定義圓圈進度並顯示百分比例控件(純代碼實現)