Android 矩形画布中的效果阴影
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10717357/
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
Effect shadow in rectangle canvas
提问by eric.itzhak
I have drawn a rectangle with canvas and I wonder if there is any property or way of giving a small shadow.
我用画布绘制了一个矩形,我想知道是否有任何属性或方法可以提供一个小阴影。
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint pincel1 = new Paint();
pincel1.setColor(Color.rgb(151, 217, 69));
RectF rectangle = new RectF(30, 20,200,100);
canvas.drawRoundRect (rectangle, 6, 6, pincel1);
}
Thanks
谢谢
回答by eric.itzhak
Thisquestion contained the following code :
这个问题包含以下代码:
Paint mShadow = new Paint();
// radius=10, y-offset=2, color=black
mShadow.setShadowLayer(10.0f, 0.0f, 2.0f, 0xFF000000);
// in onDraw(Canvas)
canvas.drawBitmap(bitmap, 0.0f, 0.0f, mShadow);
So customize it a bit to your needs and that will do the trick.
因此,根据您的需要对其进行一些自定义,这样就可以解决问题。
In your case just add pincel1.setShadowLayer(10.0f, 0.0f, 2.0f, 0xFF000000);
to your code.
在您的情况下,只需添加pincel1.setShadowLayer(10.0f, 0.0f, 2.0f, 0xFF000000);
到您的代码中。