Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
205 views
in Technique[技术] by (71.8m points)

android - Why startAnimation method doesn't work inside onTouchEvent method?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...