嘗試此自定義動畫:
class MatrixAnimation extends Animation {
private float[][] v = new float[3][9];
private ImageView target;
public MatrixAnimation(ImageView target, Matrix m0, Matrix m1) {
this.target = target;
m0.getValues(v[0]);
m1.getValues(v[1]);
setDuration(2000);
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
Matrix m = target.getImageMatrix();
for (int i = 0; i < 9; i++) {
v[2][i] = v[0][i] + (v[1][i] - v[0][i]) * interpolatedTime;
}
m.setValues(v[2]);
target.setImageMatrix(m);
}
}
起始碼:
final ImageView iv = new ImageView(this);
iv.setImageResource(R.drawable.layer0);
iv.setScaleType(ScaleType.CENTER_CROP);
LayoutParams p = new LayoutParams(LayoutParams.MATCH_PARENT, 200);
setContentView(iv, p);
OnClickListener l = new OnClickListener() {
@Override
public void onClick(View v) {
Matrix m0 = iv.getImageMatrix();
Matrix m1 = new Matrix();
Drawable d = iv.getDrawable();
RectF src = new RectF(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
RectF dst = new RectF(0, 0, iv.getWidth(), iv.getHeight());
m1.setRectToRect(src, dst, ScaleToFit.CENTER);
iv.setScaleType(ScaleType.MATRIX);
MatrixAnimation anim = new MatrixAnimation(iv, m0, m1);
iv.startAnimation(anim);
}
};
iv.setOnClickListener(l);
有生矩陣m,矩陣M = iv.getImageMatrix() – pskink
感謝。如果你能給我更詳細的信息,那麼你在這裏試圖做什麼,我將不勝感激。這將幫助我從根本上理解它。 – user2095470