Tin_Ram
Tin_Ram

Reputation: 99

onClick Animating not working? (Library)

Today is my first attempt, to implent a library in to my Android project, and I choosed this Android View Animation library, it's really good, and it's works for onCreate, but if I want to implent it to my button, the animation actually not playing. What is the problem?

Here's my code:

 public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button:
                YoYo.with(Techniques.ZoomIn)
                        .duration(700)
                        .playOn(findViewById(R.id.button));
                input.setText(null);
                Intent intent = new Intent(this, Szabaly.class);
                startActivity(intent);
                break;

Upvotes: 0

Views: 58

Answers (1)

Divers
Divers

Reputation: 9569

I think you don't realize that "playOn" method is asynchronous. It means that next line of code will be implemented right after this method, without waiting until animation would be finished.

So go ahead with this code:

YoYo.with(Techniques.ZoomIn).duration(700).withListener(new Animator.AnimatorListener() {

    @Override
    public void onAnimationStart(Animator animation) {}

    @Override
    public void onAnimationEnd(Animator animation) {

        input.setText(null);
        Intent intent = new Intent(this, Szabaly.class);
        startActivity(intent);
    }

    @Override
    public void onAnimationCancel(Animator animation) {}

    @Override
    public void onAnimationRepeat(Animator animation) {}
}).playOn(findViewById(R.id.button));

Upvotes: 1

Related Questions