【发布时间】:2018-12-15 09:58:56
【问题描述】:
我有一个疑问。在开发 App 时,我遇到了这个查询。
当一个Imageview1(较小尺寸)被拖放到Imageview2(较大尺寸)上时,如何使Imageview1(适合imageview2的区域),即Imageview1自动放大到Imageview2的尺寸。
【问题讨论】:
标签: android android-layout android-studio android-fragments layout
我有一个疑问。在开发 App 时,我遇到了这个查询。
当一个Imageview1(较小尺寸)被拖放到Imageview2(较大尺寸)上时,如何使Imageview1(适合imageview2的区域),即Imageview1自动放大到Imageview2的尺寸。
【问题讨论】:
标签: android android-layout android-studio android-fragments layout
您可以尝试一个更简单的解决方案,而不是做如此扭曲的事情:
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);
一般来说,让视图覆盖其他视图并不是一个好习惯。
【讨论】:
当你做拖拽动作时试试这个
ImageView.ScaleType(FIT_XY);
【讨论】: