【问题标题】:Android: Matrix operation on ImageView, animated?Android:ImageView上的矩阵操作,动画?
【发布时间】:2011-06-06 05:19:16
【问题描述】:

我是用矩阵来平移/缩放一个ImageView,setImageMatrix后直接显示结果,有没有办法让它动起来?

谢谢!

【问题讨论】:

  • 你在做可缩放的图像视图吗?
  • 我不确定,我只是在布局文件中将 scaleType 设置为矩阵,并在 Activity 中检测到拖动和捏合,并操作图像视图的矩阵。
  • 我的意思是说你想放大缩小图像视图
  • 是的,我想放大和缩小(以及翻译),我通过在图像视图上使用矩阵来实现,但是没有动画。

标签: android animation matrix translation imageview


【解决方案1】:

放大将是平移和缩放的组合:

// zooms in to the center of the screen
mZoomIn = new AnimationSet(true);

mTranslate = new TranslateAnimation(
                Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, -imageViewXCoord/(mScreenWidth/mImageViewWidth),
                Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, -imageViewYCoord/(mScreenWidth/mImageViewWidth)
            );
mTranslate.setDuration(200);

mScale = new ScaleAnimation(1, mScreenWidth/mImageViewWidth, 1, mScreenWidth/mImageViewWidth);
mScale.setDuration(200);

mZoomIn.addAnimation(mTranslate);
mZoomIn.addAnimation(mScale);
mZoomIn.setFillAfter(true);
mZoomIn.setFillEnabled(true);

mImageView.startAnimation(mZoomIn);

缩小将涉及放大时的反向插值器,之后您可以照常在图像视图上调用 startAnimation:

mZoomIn.setInterpolator(new ReverseInterpolator())

【讨论】:

    【解决方案2】:

    您可以尝试使用 Honeycomb 中引入的新动画框架,但我不知道这是否可以直接用于图像矩阵。您可以将使用矩阵应用的转换转换为基本动画转换,例如缩放、平移、旋转、alpha。

    如果您的目标是 Android 2.x 设备,您可以使用 Jake Wharton 的 NineOldAndroids [1],它是 Honeycomb 新动画框架的向后移植。它非常易于使用,因为它模仿了您在 11 台以上设备上使用的 API。

    [1]http://nineoldandroids.com/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多