さまざまなアニメーションを使用してプロジェクトを処理しているときに、アニメーション中に[表示]をクリックすることができないことがわかりました。アニメーション中にオンクリックしても表示されない
onClickは、アニメーションの終了点または開始点のいずれかでのみ動作しますが、その間は動作しません。
たとえば、カスタムImageViewを拡張するCarオブジェクトがあります。そして、私は車を画面上で動かしたいと思っています。目的は、移動中に車をクリック可能にすることです。そのため、運転中のアニメーションユーザーはそれをクリックして何らかのアクションを実行できます。コード上で与えられた
public class Car extends GraphicObject{
public Car(Context context, int resourceImage, int rawHeight, int rawWidth) {
super(context, resourceImage, rawHeight, rawWidth);
setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Log.d(TAG, "Works while animated.");
}
});
}
public void startMoving(int duration) {
Animation animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, +7f,
Animation.RELATIVE_TO_SELF, -7f,
Animation.RELATIVE_TO_SELF, 0f,
Animation.RELATIVE_TO_SELF, 0f
);
animation.setRepeatCount(Animation.INFINITE);
animation.setRepeatMode(Animation.RESTART);
animation.setDuration(duration);
startAnimation(animation);
}
}
だけ車が移行を完了することになっている領域にのonClickを行います。残念ながら移行中は何も動作しません。
アニメーションの切り替え中にオブジェクトをクリック可能にする方法はありますか?実際にアニメーションなしでオブジェクトを移動したくないのは、私には多大な不便をもたらすからです。
'Animation'sを使用しないでください。代わりに' Animator'sを使用してください – pskink
Animatorがこの問題を解決する方法を教えてください。 – NickitaX
https://developer.android.com/guide/topics/graphics/prop-animation.html、最も簡単な方法はhttps://developer.android.com/guide/topics/graphics/prop-animation.html#viewです-prop-animator – pskink