【问题标题】:IMAGE VIEW ANDROID STUDIO图像查看安卓工作室
【发布时间】:2018-12-15 09:58:56
【问题描述】:

我有一个疑问。在开发 App 时,我遇到了这个查询。

当一个Imageview1(较小尺寸)被拖放到Imageview2(较大尺寸)上时,如何使Imageview1(适合imageview2的区域),即Imageview1自动放大到Imageview2的尺寸。

【问题讨论】:

    标签: android android-layout android-studio android-fragments layout


    【解决方案1】:

    您可以尝试一个更简单的解决方案,而不是做如此扭曲的事情:

    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);
    

    一般来说,让视图覆盖其他视图并不是一个好习惯。

    【讨论】:

    • 实际上目的是让用户拖动图像并放置它,以便它占据那个区域,使它看起来像一个拼图。有什么想法吗?
    • 你能更详细地解释一下这个问题吗?也许使用显示状态的 gif 或矩阵?
    • 简单,2 个图像视图。一个 imageview 是一个更大尺寸的空白空间,第二个 imageview 是一个较小的空间。拖放时,较小的需要适合较大的尺寸。我已经完成了拖放的代码,但较小的需要适合较大的
    • 出现错误 -> android.graphics.drawable.ColorDrawable 无法转换为 android.graphics.drawable.BitmapDrawable
    • 检查这个我试过 Bitmap bitmap = ((BitmapDrawable)imageview2.getDrawable()).getBitmap();位图bitmap2 = ((BitmapDrawable)imageview1.getDrawable()).getBitmap(); if(bitmap == bitmap2) { image1.setImageDrawable(bird1.getDrawable()); bird1.setVisibility(VISIBLE); }
    【解决方案2】:

    当你做拖拽动作时试试这个

    ImageView.ScaleType(FIT_XY);
    

    【讨论】:

    • 你指的是哪个imageview
    • 不,它不工作显示错误。所以我编码了 imageView1.ScaleType(FIT_XY);
    猜你喜欢
    • 2013-07-08
    • 2017-04-17
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多