欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android動態(tài)自定義圓形進度條

 更新時間:2017年03月02日 11:14:21   投稿:mrr  
這篇文章主要介紹了Android動態(tài)自定義圓形進度條,需要的朋友可以參考下

效果圖:

A.繪制圓環(huán),圓弧,文本

//1.畫圓環(huán)
//原點坐標
float circleX = width / 2;
float circleY = width / 2;
//半徑
float radius = width / 2 - roundWidth / 2;
//設置畫筆的屬性
paint.setColor(roundColor);
paint.setStrokeWidth(roundWidth);
paint.setStyle(Paint.Style.STROKE);
canvas.drawCircle(circleX, circleY, radius, paint);
//2.畫圓弧
RectF oval = new RectF(roundWidth/2,roundWidth/2,width-roundWidth/2,width - roundWidth/2);
paint.setColor(roundProgressColor);
canvas.drawArc(oval, 0, progress * 360 / max, false, paint);
//3.畫文本
paint.setTextSize(textSize);
paint.setColor(textColor);
paint.setStrokeWidth(0);
String text = progress * 100 / max + "%";
Rect bounds = new Rect();
paint.getTextBounds(text, 0, text.length(), bounds);
canvas.drawText(text, width / 2 - bounds.width() / 2, width / 2 + bounds.height() / 2, paint);

B.自定義屬性的具體步驟

具體步驟:

1. 定義屬性: 在values目錄下創(chuàng)建attrs.xml

<declare-styleable name="RoundProgress">
 <attr name="roundColor" format="color"></attr>
 <attr name="roundProgressColor" format="color"></attr>
 <attr name="textColor" format="color"></attr>
 <attr name="roundWidth" format="dimension"></attr>
 <attr name="textSize" format="dimension"></attr>
</declare-styleable>

2. 在布局文件中引用當前應用的名稱空間

3. 在自定義視圖標簽中使用自定義屬性

<com.atguigu.p2p.util.RoundProgress
  android:id="@+id/rp_home_progress"
  android:layout_width="120dp"
  android:layout_height="120dp"
  android:layout_gravity="center_horizontal"
  android:layout_marginTop="20dp"
  atguigu:roundColor="@android:color/darker_gray         <br>  atguigu:roundProgressColor="@android:color/holo_red_dark"
  atguigu:textColor="@color/text_progress"
  atguigu:roundWidth="10dp"
  atguigu:textSize="20sp"
  /> 

4. 在自定義View類的構造方法中, 取出布局中的自定義屬性值

//1.得到所有自定義屬性的數(shù)組
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RoundProgress);
//2.獲取自定義屬性的值, 如果沒有指定取默認值
roundColor = typedArray.getColor(R.styleable.RoundProgress_roundColor, Color.RED);
roundProgressColor = typedArray.getColor(R.styleable.RoundProgress_roundProgressColor, Color.GREEN);
textColor = typedArray.getColor(R.styleable.RoundProgress_textColor, Color.GREEN);
roundWidth = typedArray.getDimension(R.styleable.RoundProgress_roundWidth, UIUtils.dp2px(10));
textSize = typedArray.getDimension(R.styleable.RoundProgress_textSize, UIUtils.dp2px(20));
//3.釋放資源數(shù)據(jù)
typedArray.recycle();

C.讓圓環(huán)進度"動起來"

1.自定義RoundProgress類中提供進度屬性的getter和setter方法

2.在HomeFragment的onSuccess()中:

 github:https://github.com/ganchuanpu/P2PInvest

以上所述是小編給大家介紹的Android動態(tài)自定義圓形進度條,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!

相關文章

  • Android實現(xiàn)布局全屏

    Android實現(xiàn)布局全屏

    這篇文章主要為大家詳細介紹了Android實現(xiàn)布局全屏,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-05-05
  • Android中的binder機制詳解

    Android中的binder機制詳解

    這篇文章主要介紹了Android中的binder機制詳解,幫助大家更好的理解和學習使用Android,感興趣的朋友可以了解下
    2021-04-04
  • Android使用硬件加速的方式

    Android使用硬件加速的方式

    硬件加速是指利用設備的硬件資源來加速圖形渲染和圖像處理等操作,以提高應用程序的性能和用戶體驗,Android使用硬件加速的目的是為了提高圖形渲染的性能和效果,本文給大家詳細介紹了Android如何使用硬件加速,需要的朋友可以參考下
    2023-10-10
  • Android?drawFunctor?原理及應用詳情

    Android?drawFunctor?原理及應用詳情

    這篇文章主要介紹了Android?drawFunctor原理及應用詳情,drawFunctor是Android提供的一種在RenderThread渲染流程中插入執(zhí)行代碼機制,更多相關內容需要的小伙伴可以參考一下
    2022-08-08
  • Gradle?Build?Cache引發(fā)的Task緩存編譯問題

    Gradle?Build?Cache引發(fā)的Task緩存編譯問題

    這篇文章主要為大家介紹了Gradle?Build?Cache引發(fā)的Task緩存編譯問題,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-06-06
  • AndroidStudio不自動添加新創(chuàng)建的文件到VCS的解決辦法

    AndroidStudio不自動添加新創(chuàng)建的文件到VCS的解決辦法

    這篇文章主要介紹了AndroidStudio不自動添加新創(chuàng)建的文件到VCS的解決辦法的相關資料,需要的朋友可以參考下
    2017-03-03
  • Android 斷點下載和自動安裝的示例代碼

    Android 斷點下載和自動安裝的示例代碼

    本篇文章主要介紹了Android斷點下載和自動安裝的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-01-01
  • Android 實現(xiàn)關機的多種方式

    Android 實現(xiàn)關機的多種方式

    有段時間做系統(tǒng)hook時需要用到系統(tǒng)重啟,找了幾種重啟的方法,還有幾種關機的方法,總結一下,有此需求的同學可以選擇適合自己的方式
    2021-05-05
  • Android自定義APP全局懸浮按鈕

    Android自定義APP全局懸浮按鈕

    這篇文章主要為大家詳細介紹了Android自定義APP全局懸浮按鈕,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • 安卓逆向騰訊動漫app返回數(shù)據(jù)加密分析案例分享

    安卓逆向騰訊動漫app返回數(shù)據(jù)加密分析案例分享

    這篇文章主要為大家介紹了安卓逆向騰訊動漫app返回數(shù)據(jù)加密分析的案例分享,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步
    2022-02-02

最新評論