安卓:如何在ImageView上进行矩阵操作并实现动画效果?

7
我正在使用矩阵来转换/缩放ImageView,在setImageMatrix之后,结果直接显示,有没有办法使其动画化呢?
谢谢!

你在做可缩放的ImageView吗? - ingsaurabh
我不确定,我只是在布局文件中将scaleType设置为矩阵,并在Activity中检测拖动和缩放,并操作imageview的矩阵。 - Heuristic
我的意思是说,您想在图像视图上进行缩放。 - ingsaurabh
是的,我想要缩放(以及平移)图像,我通过在ImageView上使用矩阵来实现,但是没有动画效果。 - Heuristic
2个回答

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

0
你可以尝试使用在Honeycomb中引入的新动画框架,但我不知道这是否能直接与图像矩阵配合使用。你可以将你正在应用的矩阵转换为基本的动画变换,比如缩放、平移、旋转、透明度等。
如果你的目标是Android 2.x设备,你可以使用Jake Wharton的NineOldAndroids [1],它是Honeycomb新动画框架的后移版本。它非常容易使用,因为它模仿了在11+设备上使用的相同API。
[1] http://nineoldandroids.com/

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接