onDraw を実装するカスタム ビューがあり、背景と右上の小さなオーバーレイ イメージを正常に描画します。そのオーバーレイ画像 (ScaleAnimation と Rotate Animation を含む AnimationSet) を手動でアニメーション化するには、次のようにします。
final AnimationSet animationSet = new AnimationSet(false);
animationSet.addAnimation(scaleAnimation);
animationSet.addAnimation(rotationAnimation);
animationSet.setFillAfter(true);
post(new Runnable() {
@Override
public void run () {
animationSet.start();
new Handler().post(getAnimationRunnable(animationSet));
}
private Runnable getAnimationRunnable (final AnimationSet animationSet) {
return new Runnable() {
@Override
public void run () {
final Transformation outTransformation = new Transformation();
if (animationSet.getTransformation(System.currentTimeMillis(), outTransformation)) {
// store matrix for applying in onDraw
mMatrix = outTransformation.getMatrix();
// THIS INVALIDATE DOESN'T WORK
parent.invalidate(new Rect(getParentInvalidateRect()));
post(getAnimationRunnable(animationSet));
}
}
};
}
});
このようにカスタムビューを無効にすると...
// THIS INVALIDATE DOES WORK
invalidate(getOverlayClientRect());
その後、アニメーションが発生し、アニメーション画像がクリップされることを除いて、すべてが素晴らしいです-上と右の境界を超えて拡大されているためです。
しかし、カスタム ビューの右上隅の領域と交差する parent.invalidate() に Rect を渡すと、カスタム ビューの onDraw がトリガーされません。
そう ...
- このアプローチは機能しますか?
- もしそうなら、それがカスタム Views onDraw メソッドを呼び出すかどうかを決定する、parent.invalidate() に渡された Rect 以外の要因はありますか?