设置不透明度为PictureDrawable [英] Set opacity to PictureDrawable

查看:283
本文介绍了设置不透明度为PictureDrawable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个忠告与设置不透明,因为平常 PictureDrawable 对象 setAlpha()未实现在 PictureDrawable
我的情况是类似这个 pretty(我也让我的使用库从原料资源SVGs可绘制)。但我不能使用该解决方案,因为我想(通过在创建应用彩色滤光片不)动态改变的不透明度。

I need a piece of advice with setting opacity to a PictureDrawable object since usual setAlpha() is not implemented in PictureDrawable. My case is pretty similar to this one (I also get my drawables from SVGs in raw resources using a library). But I cannot use the solution because I would like to change the opacity dynamically (not by applying color filter at creation).

上绘画时,上下文多个动画可绘制一个 SurfaceView

The context is animating multiple drawables when drawing on a SurfaceView.

有什么能在这种情况下,一个好的解决方法吗?

What could be a good workaround in this situation?

感谢您。

推荐答案

幸得@pskink,我就详细说明这一点作进一步的引用。
这是我在的onDraw(帆布油画)方法做(在我的情况 INT不透明变化反复从0到255 ):

Credit goes to @pskink, I'll just elaborate it a little for further references. This is what I do in onDraw(Canvas canvas) method (in my case int opacity changes iteratively from 0 to 255):

int width = drawable.getIntrinsicWidth();
int height = drawable.getIntrinsicHeight();

canvas.saveLayerAlpha(x, y, x + width, y + height, opacity,
                                  Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);

drawable.setBounds(x, y, x + width, y + height);
drawable.draw(canvas);
canvas.restore();

这个答案还提供了 saveLayerAlpha很好的指导()用法。

这篇关于设置不透明度为PictureDrawable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆