I'm trying to start the animation when I touch the screen but doesn't work.
Code
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imgCircle = (ImageView) findViewById(R.id.img_circle);
up = AnimationUtils.loadAnimation(MainActivity.this, R.anim.up);
up.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
imgCircle.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
imgCircle.startAnimation(up);
}
return super.onTouchEvent(event);
}
But if I removed imgCircle.startAnimation(up);
from onTouchEvent and put it in onCreate then will work well.
Can someone tells me why doesn't work inside onTouchEvent?
question from:
https://stackoverflow.com/questions/65641555/why-startanimation-method-doesnt-work-inside-ontouchevent-method 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…