android - Image is not repeating when finish once -




i want show number of images fade in fade out animation it's working fine images not repeating when complete once. want show in loop, not getting missing 1 have idea it?

my code looks below

mainactivity.java

animationfadein = animationutils.loadanimation(this, r.anim.anim_fade_in);         animationfadeout = animationutils.loadanimation(this, r.anim.anim_fade_out);          animation.animationlistener animlistener = new animation.animationlistener() {              @override             public void onanimationstart(animation animation) {             }              @override             public void onanimationrepeat(animation animation) {             }              @override             public void onanimationend(animation animation) {                  changeimage(animation);             }         };          // set listener animation         animationfadein.setanimationlistener(animlistener);         animationfadeout.setanimationlistener(animlistener);          // start fade-in animation         imgbanner.setimageresource(r.mipmap.banner1);         imgbanner.startanimation(animationfadein);   public void changeimage(animation animation) {         if (animation == animationfadein) {              // start fade-out animation             imgbanner.startanimation(animationfadeout);          } else if (animation == animationfadeout) {              count++;              // set next image after fading out previous image             switch (count) {                 case 1:                     imgbanner.setimageresource(r.mipmap.banner2);                     imgbanner.startanimation(animationfadein);                     break;                 case 2:                     imgbanner.setimageresource(r.mipmap.banner3);                     imgbanner.startanimation(animationfadein);                     break;                 case 3:                     imgbanner.setimageresource(r.mipmap.banner4);                     imgbanner.startanimation(animationfadein);                     break;                 case 4:                     imgbanner.setimageresource(r.mipmap.banner5);                     imgbanner.startanimation(animationfadein);                     break;                  default:                     break;             }         }     } 

anim_fade_in.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"     android:interpolator="@android:anim/linear_interpolator">     <alpha         android:duration="2000"         android:fromalpha="0.1"         android:toalpha="1.0" /> </set> 

anim_fade_out.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"     android:interpolator="@android:anim/linear_interpolator">     <alpha         android:duration="2000"         android:fromalpha="1.0"         android:toalpha="0.1" /> </set> 

from understand, want changeimage function's switch case loop once have reached count = 4. can place count = count % 4 before switch case. way count remain within 0-3 , can cycle through images correctly. need change switch cases. code becomes :

else if (animation == animationfadeout) {          count++;         count = count % 4; // enable recycling count variable          // set next image after fading out previous image         switch (count) {             case 0: // change cases such count values form 0-3 addressed                 imgbanner.setimageresource(r.mipmap.banner2);                 imgbanner.startanimation(animationfadein);                 break;             case 1:                 imgbanner.setimageresource(r.mipmap.banner3);                 imgbanner.startanimation(animationfadein);                 break;             case 2:                 imgbanner.setimageresource(r.mipmap.banner4);                 imgbanner.startanimation(animationfadein);                 break;             case 3:                 imgbanner.setimageresource(r.mipmap.banner5);                 imgbanner.startanimation(animationfadein);                 break;              default:                 break;         } 

currently count becomes 5 @ 1 point , switch case ignores it, not running animation.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -