-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRotateAnimation.java
More file actions
62 lines (49 loc) · 1.55 KB
/
RotateAnimation.java
File metadata and controls
62 lines (49 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.tao.view;
import android.graphics.Bitmap;
import android.graphics.Camera;
import android.graphics.Matrix;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.Transformation;
import android.widget.ImageView;
public class RotateAnimation extends Animation {
private int mCenterX;
private int mCenterY;
private Camera mCamera;
private ImageView mImageView;
private Bitmap mBitmap;
public RotateAnimation(ImageView imageView, Bitmap targetBitmap) {
this.mImageView = imageView;
this.mBitmap = targetBitmap;
}
@Override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
mCamera = new Camera();
mCenterX = width / 2;
mCenterY = height / 2;
setDuration(300);
setFillAfter(true);
setInterpolator(new LinearInterpolator());
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
Matrix matrix = t.getMatrix();
mCamera.save(); //保存当前状态
if (interpolatedTime > 0.5f) { //当动画进行到一半的时候,替换图片
mImageView.setImageBitmap(mBitmap);
}
mCamera.rotateY(180f * interpolatedTime);//旋转180°
mCamera.getMatrix(matrix);
matrix.preTranslate(-mCenterX, -mCenterY);
matrix.postTranslate(mCenterX, mCenterY);
mCamera.restore(); //载入之前保存的状态
}
public void setTargetBitmap(Bitmap targetBitmap) {
mBitmap = targetBitmap;
}
public void setImageView(ImageView imageView) {
mImageView = imageView;
}
}