I am trying to create animation in Android like this
Animation example[
^]. I am using fade-in fade-out effects and PNG images saved in R drawable folder. All the images have the same dimensions. Therefore, I want to achieve the animation like the one shown in the above web URL.
The problem is fade-in and fade-out effects are quite prominent, it's hard to see what's happening in the changing pictures. How can I make simultaneous fade-in fade-out effects so that the fading effect is not prominent, and I can achieve animation effect shown in the above web URL?
For animation, I am using images stored from drawable resources. Can one also load images directly from web URL and animate?
What I have tried:
Here is the method that animates the images. For the time being, I am using images stored in drawable resource folder.
private void animate(final ImageView imageView, final int images[], final int imageIndex, final boolean forever){
int fadeInDuration = 100;
int timeBetween = 100;
int fadeOutDuration = 100;
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 Animation.AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
if(images.length -1 > imageIndex){
animate(imageView, images, imageIndex + 1, forever);
}
else{
if(forever == false){
animate(imageView, images, 0, forever);
}
}
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationStart(Animation animation) {
}
});
}