Drawable的深层副本 [英] Deep copy of a Drawable

查看:149
本文介绍了Drawable的深层副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ImageView。在它的onClick我得到它的Drawable:

I have an ImageView. In its onClick I get its Drawable:

Drawable dr = ((ImageView) v).getDrawable();

并将其设置为对话框的ImageView:

And set it to a dialog's ImageView:

zoomedImage.setImageDrawable(dr);

但是当我关闭对话框或活动恢复时。原始位置的图像被拉伸并显示大于其大小,导致图像中只有一部分图像可见。

But when I close the dialog or the activity is resumed. The image at the original position gets stretched and is shown larger than its size, leading to only a portion of the image is visible in the ImageView.

这是一个案例吗?深拷贝还是有另一个问题?
如果是,如何深度复制原始Drawable以便我可以将副本设置为缩放图像?

Is this a case of deep copy or there is another problem? If it is, how can do I deep copy the original Drawable so that I could set the copy to zoomed image?

提前致谢。

推荐答案

最后我成功了!
我有类似的问题,当我在我的drawable上使用彩色滤镜时它改变了drawable,它非常接近其他人的解决方案,但只有这对我有用:

Finally I succeed! I had similar problem, when I used color filter on my drawable it changed the drawable, its very close to the solution of the other people here, but only this worked for me:

Drawable drwNewCopy = dr.getConstantState().newDrawable().mutate();

这篇关于Drawable的深层副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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