圓形進度條

2021-09-01 14:17:33 字數 2174 閱讀 9907

public class circleprogress extends view 

public int getmheight()

public void setmheight(int mheight)

public int getmwidth()

public void setmwidth(int mwidth)

public int getmorbitwidth()

public void setmorbitwidth(int morbitwidth)

public int getmtextsize()

public void setmtextsize(int mtextsize)

public boolean ismenabletext()

public void setmenabletext(boolean menabletext)

public int getmcolorprogress()

public void setmcolorprogress(int mcolorprogress)

public int getmcolororbit()

public void setmcolororbit(int mcolororbit)

public int getmcolortext()

public void setmcolortext(int mcolortext)

public int getmmaxprogress()

public void setmmaxprogress(int mmaxprogress)

public int getmprogress()

public void setmprogress(int mprogress)

public paint getmpaint()

public void setmpaint(paint mpaint)

public int getmradius()

public void setmradius(int mradius)

public circleprogress(context context)

public circleprogress(context context, attributeset attrs)

public circleprogress(context context, attributeset attrs, int defstyleattr)

@override

protected void ondraw(canvas canvas) else

int cx = getwidth()/2;

int cy = getheight()/2;

//畫進度條軌道

mpaint.setcolor(mcolororbit); //設定圓的顏色

mpaint.setstyle(paint.style.stroke); //設定空心

mpaint.setstrokewidth(morbitwidth); //設定圓的寬度

mpaint.setantialias(true); //消除鋸齒

canvas.drawcircle(cx, cy, mradius, mpaint); //畫出圓

//畫進度(圓弧)

mpaint.setcolor(mcolorprogress); //設定進度的顏色

rectf oval = new rectf(cx-mradius,cy-mradius,cx+mradius,cy+mradius);

canvas.drawarc(oval, -90, 360 * (mprogress*1f / mmaxprogress), false, mpaint); //根據進度畫圓弧

//畫圓環內百分比文字

if (menabletext)

}public void setprogress(int progress)

@override

protected void onmeasure(int widthmeasurespec, int heightmeasurespec)

public string getprogresstext()

}

canvas圓形進度條

canvas中沒有直接繪製圓的方法,但有乙個繪製弧線的context.arc方法,下面講下用該方法如何繪製出效果。引數說明 看到這裡,大家就會明白怎麼畫圓了把,只要讓起始角和結束角度為乙個圓周就可以了。下面開始畫圖咯!環形進度條主要兩部分組成,一是灰色圓,另一是藍色弧度。也就是說灰色圓圈和藍色弧同圓...

IOS 圓形進度條

demo created by leao on 2017 8 7.import typedef ns enum nsinteger,ccprogressviewstyle inte ce ccprogressview uiview property nonatomic,assign,setter s...

canvas 圓形進度條

canvas width 800 height 800 style border 1px solid ccc canvas const can document.getelementbyid canvas const van can.getcontext 2d let currentdeg 0 度從...