1

I have used an imageView to display 5 nearly equal images randomly on the screen.The thing is every image is turned off and immediately next one is displayed.So that the viewer can easily find that image is being changed.Is it possible to add animation effects to imageView? (like, one image slowly fades out,in the meanwhile another image fades in)

Akhil Reddy
  • 371
  • 1
  • 6
  • 26
  • https://stackoverflow.com/a/6822116/5505680 there is the FADE-in - out, combine it to have the desired slution – matheszabi Jun 12 '17 at 11:39

1 Answers1

0

u can modify ur self

ImageView img_view= (ImageView) findViewById(R.id.DemoImage);

int images[] = { R.drawable.image1, R.drawable.image2,R.drawable.image3 };

animate(img_view, images, 0,false);  

private void animate(final ImageView imageView, final int images[], final int imageIndex, final boolean forever) {

    int fadeInDuration = 1000; 
    int timeBetween = 5000;
    int fadeOutDuration = 1000;

    imageView.setVisibility(View.INVISIBLE);    
    imageView.setImageResource(images[imageIndex]);

    Animation fadeIn = new AlphaAnimation(0, 1);
    fadeIn.setInterpolator(new DecelerateInterpolator()); 
    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); 
    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); 
            }
            else {
                if (forever){
                animate(imageView, images, 0,forever);  
                }
            }
        }

    });
}