Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 986
hzxu Avatar asked Jun 06 '11 05:06

hzxu


1 Answers

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())
like image 181
Dhruv Gairola Avatar answered Oct 08 '22 21:10

Dhruv Gairola