Deep copy of a Drawable

前端 未结 4 775
旧时难觅i
旧时难觅i 2020-12-06 09:16

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

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

And set it to a dialog\'s ImageView:

4条回答
  •  無奈伤痛
    2020-12-06 09:49

    I managed to copy the drawable using following code:

    drawable.mutate().getConstantState().newDrawable();
    

    Here mutate() makes the drawable mutable to avoid sharing its state, and getConstantState().newDrawable() creates a new copy.

    Thus different ImageViews use different drawables and there's no stretching.

提交回复
热议问题