Android 如何画一个中间透明的圆

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3487216/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 10:25:48  来源:igfitidea点击:

How to draw a circle with a transparent middle

android

提问by FrinkTheBrave

I am trying to draw a white circle with the following code:

我正在尝试使用以下代码绘制一个白色圆圈:

mPaint.setColor(0xFFFFFFFF);
canvas.drawCircle(x, y, radius, mPaint);

But it is being displayed as a solid disk. How do I get it to just display as a circular outline with a transparent centre?

但它显示为固态磁盘。如何让它仅显示为具有透明中心的圆形轮廓?

I've had a look in the help and it makes no sense to me, probably because I'm not used to the drawing terms like stroke and dither. What's wrong with background and border, eh?

我看过帮助,但对我来说毫无意义,可能是因为我不习惯笔画和抖动等绘图术语。背景和边框有什么问题,嗯?

回答by Jon Skeet

I suspect you want:

我怀疑你想要:

mPaint.setStyle(Paint.Style.STROKE);

so that it doesn't do the filling. But then again, I've never used the Android API - this is really just a guess based on the docs :)

这样它就不会填充。但是话又说回来,我从未使用过 Android API - 这实际上只是基于文档的猜测:)