自定義儀表盤

weixin_34082695發表於2017-10-09

1.前言

由於專案需要實現一個類似於儀表盤的功能顯示當前裝置的狀態,就像各個手機衛士主頁的評分控制元件。

2.實現

  1. 起初還是一如既往,有沒有現成的,有的話直接用或者改一改,簡單方便,但後來沒有找到一個適合我專案的開源儀表控制元件,參考了一些相關控制元件後決定自己寫一個,雖然自定義View可能是安卓裡最弱的一項,但這個還是很簡單的。

2.需要實現進度條平滑的遞增,一個簡單的動畫,其次可以實現任意角度的圓形進度,第三實現漸變色(這個search好久才查到可能很少人用的原因,也可能是我自定義View有點row).

3.碼區

attr程式碼
<attr name="is_dashed_circular" format="boolean"/>       <!--是否是虛線-->
<attr name="max_visible_arc" format="integer"/>          <!--最大角度-->
<attr name="progress_count" format="integer" />          <!--當前進度-->
<attr name="each_progress_width" format="integer"/>      <!--每個進度的寬度-->
<attr name="each_progress_height" format="integer" />    <!--每個進度的高度-->
<attr name="central_width" format="integer"/>            <!--第二個圓環的寬度-->
<attr name="finished_progress_color" format="color"/>    <!--完成的進度顏色-->
<attr name="unfinished_progress_color" format="color"/>  <!--未完成進度的顏色-->
<attr name="fill_center_color" format="color"/>          <!--內圓顏色-->
<attr name="fill_central_color" format="color"/>         <!--第二個圓環的顏色-->

其他的可以看程式碼就一個類

4.效果圖

2646598-fe9fe4f0cc673caa.png
img1.png
2646598-f75dd23bee901b99.gif
img2.gif

5.github地址

相關文章