0
在觸摸事件上,創建自定義的可繪製視圖,添加到根視圖,以便它顯示在屏幕上,然後我有一個淡入淡出動畫,以淡化它。這一切都在工作,但沒有壓力!如何確保視圖在重複觸摸後被移除動畫
當我重複執行觸摸事件,例如一秒鐘內快速觸摸3次時,自定義繪圖出現在屏幕上。
這是爲什麼?我希望每次都刪除它。下面的代碼:
/*
* Adds view and fades out
*/
public void fadeoutView(final View v){
if (rootView != null) {
rootView.removeView(v);
}
rootView.addView(v);
Log.v(LOG_TAG, "Fadeout called");
final Animation fadeOut = new AlphaAnimation(1.0f, 0.0f);
fadeOut.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
Log.v(LOG_TAG, "Fadeout onAnimationStart t:" + System.currentTimeMillis());
}
@Override
public void onAnimationEnd(Animation animation) {
Log.v(LOG_TAG, "Fadeout onAnimationEnd t:" + System.currentTimeMillis());
if (v != null && rootView != null) {
rootView.removeView(v);
}
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
fadeOut.setFillAfter(true); // Want to keep affect
fadeOut.setInterpolator(new DecelerateInterpolator());
fadeOut.setStartOffset(0);
fadeOut.setDuration(500);
if (v != null) {
v.startAnimation(fadeOut);
}
}
這是從UIThread內公共布爾onTouch(查看視圖,MotionEvent motionEvent)