Android Animation Repeating -


i have 3 views same translate animation. using random number 0-2, 1 of 3 views animated. i'm having trouble repeating animation , delay of each animation each other (should around 2000ms).

animation move = animationutils.loadanimation(this, r.anim.move); view view1 = (view) findviewbyid(r.id.view1); view view2 = (view) findviewbyid(r.id.view2); view view3 = (view) findviewbyid(r.id.view3);  random color_box_fall_random = new random(); int random_int = (color_box_fall_random.nextint(2));  (int = 0; < 10; i++){     if (random_int == 0){         view1.startanimation(move);     }     else if (random_int == 1){         view2.startanimation(move);     }     else{         view3.startanimation(move);     } } 

move.xml

<?xml version="1.0" encoding="utf-8"?> <set     xmlns:android="http://schemas.android.com/apk/res/android"     android:interpolator="@android:anim/linear_interpolator">      <translate         android:startoffset="2000"         android:fromydelta="-200"         android:toydelta="50%p"         android:duration="2000" /> </set> 

you need use animationlistener start next animation after 1 ends. can post runnable 2 second delay delay.

animation move; view view1; view view2; view view3; random color_box_fall_random; int i; handler handler;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      move = animationutils.loadanimation(this, r.anim.move);     view1 = findviewbyid(r.id.view1);     view2 = findviewbyid(r.id.view2);     view3 = findviewbyid(r.id.view3);      color_box_fall_random = new random();      handler = new handler();      move.setanimationlistener(new animation.animationlistener() {         @override         public void onanimationstart(animation animation) {          }          @override         public void onanimationend(animation animation) {             i++;             if(i < 10) {                 handler.postdelayed(new runnable() {                     @override                     public void run() {                         switch(color_box_fall_random.nextint(2)){                             case 0:                                 view1.startanimation(move);                                 break;                             case 1:                                 view2.startanimation(move);                                 break;                             case 2:                                 view3.startanimation(move);                                 break;                         }                     }                 }, 2000);             }         }          @override         public void onanimationrepeat(animation animation) {          }     });      switch(color_box_fall_random.nextint(2)){         case 0:             view1.startanimation(move);             break;         case 1:             view2.startanimation(move);             break;         case 2:             view3.startanimation(move);             break;     } } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -