Android: Matrix operation in ImageView, animated?

I use the matrix to translate / scale the ImageView, after setImageMatrix, the result is shown directly, is there any way to make it animated?

Thanks!

+4
source share
2 answers

Scaling would be a combination of both translations 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); 

When scaling, the inverse interpolator will be used when scaling, after which you can call startAnimation on your image in accordance with the normal one:

 mZoomIn.setInterpolator(new ReverseInterpolator()) 
+1
source

You can try using the new animation structure introduced in Honeycomb, but I don’t know if this will work directly with image matrices. You can transform the transformation that you apply with your matrix to elementary transformations of the animation, such as scaling, translation, rotation, alpha.

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

[1] http://nineoldandroids.com/

0
source

All Articles