【问题标题】:Scaling (or Adding) Two Images in Android在 Android 中缩放(或添加)两个图像
【发布时间】:2014-08-27 11:24:10
【问题描述】:

我有一个接受用户输入的活动。然后,我有一个显示屏幕大小的 ImageView (ImageOne) 的活动。为此,我将其缩放 centerCrop。但是,根据用户输入,在 ImageOne 上会出现另一个较小的图像(ImageTwo,它会根据输入而变化)。有没有办法基于 ImageOne 的缩放来缩放 ImageTwo,或者添加两个图像然后在同一个 ImageView 中缩放它们。

谢谢, 迈克尔

【问题讨论】:

    标签: android android-activity imageview android-imageview


    【解决方案1】:

    将维度保存在 res>values>dimens 中并使用相同的维度,例如 getResources().getDimension(R.id.yourDimension) 用于缩放两个图像

    //在尺寸文件中

     <integer name="yourDimension">20</integer> 
    

    【讨论】:

    • 我正在使用 picaso,所以我的代码就像这样 Picasso.with(context).load(R.drawable.yourImageResource).resize(getResources().getDimension(R.id.yourDimension), getResources ().getDimension(R.id.yourDimension)).centerCrop().into(R.id.yourImageView);
    【解决方案2】:

    但是,根据用户输入,我需要添加另一个较小的图像 (ImageTwo) 在 ImageOne 之上。

    为什么不试试FrameLayout,其中ImageOne 处于较低级别而ImageTwo 处于较高级别?保持ImageTwo 隐藏,当用户让你继续时,让它可见。由于它是一个较小的图像,因此会看到您较低的ImageOne。

    如果您在用户提供输入时确实需要替换ImageOne 的像素,那么您还有一些工作要做。您首先必须获得ImageOne 的Bitmap,然后在做一些数学运算后,使用replacePixels() 将像素替换为ImageTwo 的像素。这取决于你的要求,真的。

    资源:
    FrameLayout

    【讨论】:

      猜你喜欢
      • 2012-01-31
      • 1970-01-01
      • 2020-07-24
      • 1970-01-01
      • 2013-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多