本文介绍了绘制在Android画布空心圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作创建一个自定义视图,用户可以选择的角度。下面是最终的结果应该是什么样子的例子:

I am working on creating a custom view where a user can select an angle. Below is an example of what the end result should look like:

我用下面的code实现这一目标:

I am achieving this with the following code:

mPaint.setColor(Color.BLACK);
canvas.drawCircle((int) (mSize.right / 2), (int) (mSize.bottom / 2),
        mWidthOutside, mPaint);

mPaint.setColor(Color.LTGRAY);
canvas.drawCircle((int) (mSize.right / 2), (int) (mSize.bottom / 2),
        mWidthInside, mPaint);

通过做这种方式的问题,就是背景是一个静态 LTGRAY ,我希望能够透明。

The problem with doing it this way, is the background is a static LTGRAY, which I hope to make Transparent.

我怎么会去离开圆心透明?

How would I go about leaving the center of the circle transparent?

我曾尝试以下的,希望在 drawArc 功能只会造成一条线涂料的宽度,而不是填补了中心。它在面对填充的中心。

I have tried the following hoping the the drawArc function would only create a line the width of the paint, and not fill the center. It does in face fill the center.

RectF rectF = new RectF(centerX - mRadius, centerY - mRadius, centerX
            + mRadius, centerY + mRadius);
canvas.drawArc(rectF, 0, 360, false, mPaint);

这是如何保持圆心建议透明?

Suggestions on how to keep the center of the circle transparent?

推荐答案

由于问:)
解决的办法是设置样式为 Paint.Style.STROKE

这篇关于绘制在Android画布空心圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 20:17