国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Android > 正文

Android動(dòng)態(tài)自定義圓形進(jìn)度條

2019-10-23 19:44:04
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

效果圖:

android,自定義圓形進(jìn)度條,圓形進(jìn)度條

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

//1.畫(huà)圓環(huán)//原點(diǎn)坐標(biāo)float circleX = width / 2;float circleY = width / 2;//半徑float radius = width / 2 - roundWidth / 2;//設(shè)置畫(huà)筆的屬性paint.setColor(roundColor);paint.setStrokeWidth(roundWidth);paint.setStyle(Paint.Style.STROKE);canvas.drawCircle(circleX, circleY, radius, paint);//2.畫(huà)圓弧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.畫(huà)文本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. 在布局文件中引用當(dāng)前應(yīng)用的名稱(chēng)空間

xmlns:atguigu=http://schemas.android.com/apk/res-auto

3. 在自定義視圖標(biāo)簽中使用自定義屬性

<com.atguigu.p2p.util.RoundProgress  android/168359.html">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類(lèi)的構(gòu)造方法中, 取出布局中的自定義屬性值

//1.得到所有自定義屬性的數(shù)組TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RoundProgress);//2.獲取自定義屬性的值, 如果沒(méi)有指定取默認(rèn)值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)進(jìn)度"動(dòng)起來(lái)"

1.自定義RoundProgress類(lèi)中提供進(jìn)度屬性的getter和setter方法

2.在HomeFragment的onSuccess()中:

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

以上所述是小編給大家介紹的Android動(dòng)態(tài)自定義圓形進(jìn)度條,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)VEVB武林網(wǎng)網(wǎng)站的支持!


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到Android開(kāi)發(fā)頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 广宗县| 朝阳县| 德庆县| 宁南县| 清徐县| 阿合奇县| 禄丰县| 弋阳县| 辽宁省| 本溪| 哈尔滨市| 马边| 瑞安市| 嵊州市| 朝阳区| 平陆县| 合水县| 微山县| 丰顺县| 丹棱县| 扎赉特旗| 乡宁县| 留坝县| 宁南县| 卓尼县| 尼勒克县| 沙田区| 应用必备| 沂南县| 自治县| 邯郸市| SHOW| 周至县| 青铜峡市| 闵行区| 朔州市| 漳平市| 普洱| 股票| 长海县| 南昌市|