我有个疑问。在开发 App 时,我遇到了这个查询。
当一个Imageview1(较小尺寸)拖放到Imageview2(较大尺寸)上时,如何使Imageview1(适合imageview2的区域),即自动将Imageview1放大到Imageview2的尺寸。
您可以尝试更简单的解决方案,而不是做如此扭曲的事情,例如:
ImageView2.setImageDrawable(ImageView1.getDrawable());
ImageView1.setVisibility(INVISIBLE); //GONE could be used too, depending on the situation
覆盖 ImageView2 将涉及许多其他操作,例如在布局内移动 ImageView1、设置新的 LayoutParams 等。
编辑
用这个:
ImageView1.buildDrawingCache();
Bitmap src = ImageView1.getDrawingCache();
BitmapDrawable destDrawable = new BitmapDrawable(Bitmap.createScaledBitmap(src, ImageView2.getWidth(), ImageView2.getHeight(), false));
ImageView2.setImageDrawable(destDrawable);
一般来说,让视图覆盖其他视图并不是一个好习惯。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句