这期内容当中小编将会给大家带来有关在Android开发中通过自定义View实现一个圆形进度条,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。首先来看看自己定义的Viewpackage cn.easymobi
这期内容当中小编将会给大家带来有关在Android开发中通过自定义View实现一个圆形进度条,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
首先来看看自己定义的View
package cn.easymobi.application.bell.common;import android.content.Context;import android.graphics.canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.RectF;import android.util.AttributeSet;import android.view.View;public class ProgressView extends View{ private float fArcNum; private float fMax; private float density; public float getDensity() { return density; } public void setDensity(float density) { this.density = density; } public ProgressView(Context context) { super(context); } public ProgressView(Context context,AttributeSet attrs) { super(context,attrs); } protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); Paint paint=new Paint(); if(fArcNum>0) { paint.setColor(Color.GRAY); paint.setFlags(Paint.ANTI_ALIAS_FLAG); canvas.drawCircle(40*density/2, 40*density/2, 40*density/2, paint); } paint.setColor(Color.YELLOW); paint.setFlags(Paint.ANTI_ALIAS_FLAG); //paint.setStrokeWidth(2); RectF rect=new RectF(0, 0, 40*density, 40*density); canvas.drawArc(rect, -90, fArcNum,true, paint); paint.setColor(Color.BLACK); paint.setFlags(Paint.ANTI_ALIAS_FLAG); canvas.drawCircle(40*density/2, 40*density/2, 40*density/2-5, paint); } public void setProgress(float num) { fArcNum = (num/fMax) * 360; } public float getfArcNum() { return fArcNum; } public void setfArcNum(float fArcNum) { this.fArcNum = fArcNum; } public float getfMax() { return fMax; } public void setfMax(float fMax) { this.fMax = fMax; }}
--结束END--
本文标题: 在Android开发中通过自定义View实现一个圆形进度条
本文链接: https://lsjlt.com/news/224988.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0