gpt4 book ai didi

android - 电池圈像 Battery Widget Reborn

转载 作者:太空狗 更新时间:2023-10-29 16:20:57 24 4
gpt4 key购买 nike

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

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);

我正在尝试类似于 Battery Widget Reborn,其中它是一个基于百分比绘制的圆形路径,有人可以帮忙吗。

编辑:

下面是我正在努力完成的事情的截图

image of the percentage circle

最佳答案

您可以将此类用作完整的工作示例。您还可以在 View 中添加文本,但这超出了问题范围......

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.view.View;

public class DrawView extends View {

Paint mPaint = new Paint();

public DrawView(Context context) {
super(context);
}

@Override
public void onDraw(Canvas canvas) {

Paint mPaint = new Paint(Paint.FILTER_BITMAP_FLAG |
Paint.DITHER_FLAG |
Paint.ANTI_ALIAS_FLAG);
mPaint.setDither(true);
mPaint.setColor(Color.GRAY);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(1);

int size = 200;
int radius = 190;
int delta = size - radius;
int arcSize = (size - (delta / 2)) * 2;
int percent = 42;

//Thin circle
canvas.drawCircle(size, size, radius, mPaint);

//Arc
mPaint.setColor(Color.parseColor("#33b5e5"));
mPaint.setStrokeWidth(15);
RectF box = new RectF(delta,delta,arcSize,arcSize);
float sweep = 360 * percent * 0.01f;
canvas.drawArc(box, 0, sweep, false, mPaint);

}

}

关于android - 电池圈像 Battery Widget Reborn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14988701/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com