android - How to do smooth transition from one image to another -
i have activity changing imageview periodically, wrote below line of code .
imageview.setimageuri(resid);
i increasing resource id .it works fine there sudden transition 1 image another. don't want that,i want smooth transition of image view image. how can that?
try
imageview demoimage = (imageview) findviewbyid(r.id.demoimage); int imagestoshow[] = { r.drawable.image1, r.drawable.image2,r.drawable.image3 }; animate(demoimage, imagestoshow, 0,false); private void animate(final imageview imageview, final int images[], final int imageindex, final boolean forever) { //imageview <-- view displays images //images[] <-- holds r references images display //imageindex <-- index of first image show in images[] //forever <-- if equals true after last image starts on again first image resulting in infinite loop. have been warned. int fadeinduration = 500; // configure time values here int timebetween = 3000; int fadeoutduration = 1000; imageview.setvisibility(view.invisible); //visible or invisible default - apply when animation ends imageview.setimageresource(images[imageindex]); animation fadein = new alphaanimation(0, 1); fadein.setinterpolator(new decelerateinterpolator()); // add fadein.setduration(fadeinduration); animation fadeout = new alphaanimation(1, 0); fadeout.setinterpolator(new accelerateinterpolator()); // , fadeout.setstartoffset(fadeinduration + timebetween); fadeout.setduration(fadeoutduration); animationset animation = new animationset(false); // change false animation.addanimation(fadein); animation.addanimation(fadeout); animation.setrepeatcount(1); imageview.setanimation(animation); animation.setanimationlistener(new animationlistener() { public void onanimationend(animation animation) { if (images.length - 1 > imageindex) { animate(imageview, images, imageindex + 1,forever); //calls until gets end of array } else { if (forever == true){ animate(imageview, images, 0,forever); //calls start animation on again in loop if forever = true } } } public void onanimationrepeat(animation animation) { // todo auto-generated method stub } public void onanimationstart(animation animation) { // todo auto-generated method stub } }); }
Comments
Post a Comment