像电池的Widget重生电池圈 [英] Battery circle like Battery Widget Reborn
本文介绍了像电池的Widget重生电池圈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使绘制根据电池百分比的圈子。我有以下的code:
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);
我试图得到类似电池的Widget重生的基础上,一个个在那里它是一个圆形的路径绘制的,可能有人请帮忙。
I am trying to get similar to Battery Widget Reborn, where its a circle path drawn based on a percentage, could someone please help.
编辑:
是一拍什么,我试图完成
below is a shot of what i am trying to accomplish
推荐答案
您应该能够与 Path.addArc()
做到这一点。你只需要定义的外接矩形,起始角的范围,以及多少度扫。
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.
是这样的:
RectF box = new RectF(0,0,bmp.getWidth(),bmp.getHeight());
float sweep = 360 * level * 0.01f;
circle.addArc(box, 0, sweep);
这篇关于像电池的Widget重生电池圈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文