androidandroid-handlerandroid-timer

How to run code in each time in android


I want show animation in my application, and i want show this animation each 3000m/s.
I write below code, but in this code show just once.

new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        YoYo.with(Techniques.Bounce)
                .duration(1500)
                .playOn(arrowHelpImage);
    }
}, 3000);

How can i edit my code and show each 3000m/s ?


Solution

  • U could use something like this. change the animations used below. this animations will run infinite. provide animation on end Listner. Change animation duration to 3000ms and use this in handler.it will work

    YoYo.with(Techniques.Bounce)
        .duration(1200) 
        .interpolate(new AccelerateDecelerateInterpolator())
        .withListener(new Animator.AnimatorListener() {
    
            @Override 
            public void onAnimationStart(Animator animation) {}
    
            @Override 
            public void onAnimationEnd(Animator animation) {
              YoYo.with(Techniques.Bounce)
              .duration(1200) 
              .interpolate(new AccelerateDecelerateInterpolator())
              .withListener(this).playOn(arrowHelpImage);
           }
    
            @Override 
            public void onAnimationCancel(Animator animation) {}
    
            @Override 
            public void onAnimationRepeat(Animator animation) {}
        }).playOn(arrowHelpImage);