电池圈像电池小工具重生 [英] Battery circle like Battery Widget Reborn

查看:203
本文介绍了电池圈像电池小工具重生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据电池百分比绘制一个圆圈。我有以下代码:

  Bitmap.Config conf = Bitmap.Config.ARGB_8888; //看到其他conf类型
Bitmap bmp = Bitmap.createBitmap(200,200,conf);

paint mPaint = new Paint();
mPaint.setDither(true);
mPaint.setColor(Color.BLUE);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(5);

circle = new Path();
circle.addCircle(100,100,level,Direction.CW);

Canvas canvas = new Canvas(bmp);
canvas.drawPath(circle,mPaint);

我想尝试类似于Battery Widget Reborn, ,有人可以帮忙。



编辑:



/ p>

$你应该能够使用 Path.addArc()来执行此操作。b $ b

解决方案

您只需要定义包围矩形的边界,起始角度和要扫描的度数。



像:

  RectF box = new RectF 0,bmp.getWidth(),bmp.getHeight()); 
float sweep = 360 * level * 0.01f;
circle.addArc(box,0,sweep);


I am trying to make draw a circle based on the battery percentage. I have the following code:

Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types
Bitmap bmp = Bitmap.createBitmap(200, 200, conf);

Paint mPaint = new Paint();
mPaint.setDither(true);
mPaint.setColor(Color.BLUE);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(5);

circle = new Path();
circle.addCircle(100, 100, level, Direction.CW);

Canvas canvas = new Canvas(bmp);
canvas.drawPath(circle, mPaint);

I am trying to get similar to Battery Widget Reborn, where its a circle path drawn based on a percentage, could someone please help.

Edit:

below is a shot of what i am trying to accomplish

解决方案

You should be able to do this with Path.addArc(). You just have to define the bounds of the enclosing rectangle, the start angle, and how many degrees to sweep.

Something like:

RectF box = new RectF(0,0,bmp.getWidth(),bmp.getHeight());
float sweep = 360 * level * 0.01f;
circle.addArc(box, 0, sweep);

这篇关于电池圈像电池小工具重生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆