开发者

Android: Matrix operation on ImageView, animated?

I am using matrix to translate/scale an ImageView, after setImageMatrix, the result is shown directly, is there anyway to make it animated?

开发者_开发知识库

Thanks!


Zooming in would be a combination of both translate and scale:

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

Zooming out would involve a reverse interpolator on the zoom in, after which you can call startAnimation on your image view as per normal:

mZoomIn.setInterpolator(new ReverseInterpolator())


You could try using the new Animation Framework introduced in Honeycomb, but I don't know if this will work directly with image matrices. You could convert the transformation you are applying with your matrix to elementary animation transformations, such as scale, translate, rotate, alpha.

If you are targeting Android 2.x devices you could use Jake Wharton's NineOldAndroids [1] which is a backport of the Honeycomb new Animation Framework. It is very easy to use, as it mimics the same API you would use on 11+ devices.

[1] http://nineoldandroids.com/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜