Drawable 的深拷贝

Deep copy of a Drawable(Drawable 的深拷贝)

本文介绍了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);

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

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 的深拷贝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Drawable 的深拷贝

基础教程推荐