自定义画圆
来源:互联网 发布:打电话录音软件 编辑:程序博客网 时间:2024/05/20 19:17
package aaaaa.diy.View;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.Rect;import android.graphics.RectF;import android.util.AttributeSet;import android.view.View;/** * Created by fuck on 2017/11/5. */public class huaQuan extends View{ private Paint paint; private boolean runing = true ; private int progress = 0 ; Context context; public huaQuan(Context context) { super(context); } public huaQuan(Context context, AttributeSet attrs) { this(context, attrs,0); } public huaQuan(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); //创建一个画笔 paint = new Paint(); // 抗锯齿 paint.setAntiAlias(true); //设置画笔的颜色 paint.setColor(Color.RED); //设置画笔 填充是空心的 new Thread(new Runnable() { @Override public void run() { while (runing){ if(progress >= 360){ runing = false; return; } System.out.println("progress = " + progress); progress += 10 ; //子线程刷新 系统调用onDraw() 方法 postInvalidate(); try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } } }).start(); } float sweep ; protected void onDraw(Canvas canvas) { super.onDraw(canvas); int x = getWidth() / 2; int y = getHeight() / 2; int radius = 100; paint.setStrokeWidth(20); RectF rectF = new RectF(x - radius, y - radius, x + radius, y + radius); canvas.drawArc(rectF, -90, progress, false, paint); int text = (int) ((float) progress / 360 * 100); float textWidth = paint.measureText(text + "%"); Rect rextText = new Rect(); paint.getTextBounds(text + "%", 0, (text + "%").length(), rextText); paint.setTextSize(30); paint.setStrokeWidth(1); //画文字 canvas.drawText(text + "%", x - textWidth / 2, y + rextText.height() / 2, paint); }}
阅读全文
0 0
- 自定义->画一个圆
- 自定义画圆
- 自定义画圆
- 自定义画圆+文字
- 自定义画圆
- 自定义画圆
- 自定义画圆
- 自定义画圆
- 自定义画圆与直线
- 自定义view画圆拖动
- 自定义控件画笔画圆
- 自定义View画三个圆
- 自定义view画一个圆
- 自定义控件之画圆及自定义属性
- 自定义圆
- 自定义圆
- 自定义圆
- 自定义View控件画圆,拖动圆
- Java反射机制
- 棋盘覆盖问题
- execut1
- Walk UVA
- 选择问题
- 自定义画圆
- Android O指纹识别解析
- vue学习第17天,渲染 JSX 插件
- MT 207 Request For Financial Institution Transfer金融机构转账请求
- 输油管道问题
- mongoose设置unique不生效问题解决
- 自定义画矩形
- **.js 文件 ,传参数进去
- 关于vmware虚拟机克隆的网络问题