当与另一个 ImageView 显示相同的 BitmapDrawable 时,ImageView 中的图像自动缩放?
Image in ImageView auto scale when display the same BitmapDrawable with another ImageView?
这种情况我在Android遇到过,现在还没找到解决方法
我有一个 ImageView
通过这些代码显示:
BitmapDrawable value = ...;
imageView1.setImageDrawable(value);
然后我使用 imageView2
在 Drawable
中显示相同的图像:
imageView2.setImageDrawable(value);
而且 ops,... imageView1
中的图像自动缩放并变得比旧图像更大。 (imageView2
大于 imageView1
)。
有没有人见过这种情况?
Drawables 是不可变的,所以一个位图会被缩放,然后由两个 ImageViews 显示。
要为第二个获取不同的(未共享的)版本,请尝试:
imageView2.setImageDrawable(value.mutate());
这种情况我在Android遇到过,现在还没找到解决方法
我有一个 ImageView
通过这些代码显示:
BitmapDrawable value = ...;
imageView1.setImageDrawable(value);
然后我使用 imageView2
在 Drawable
中显示相同的图像:
imageView2.setImageDrawable(value);
而且 ops,... imageView1
中的图像自动缩放并变得比旧图像更大。 (imageView2
大于 imageView1
)。
有没有人见过这种情况?
Drawables 是不可变的,所以一个位图会被缩放,然后由两个 ImageViews 显示。 要为第二个获取不同的(未共享的)版本,请尝试:
imageView2.setImageDrawable(value.mutate());