How To Blink Image In Imageview (android)
I am working on a wallpaper app in which I am displaying image with ImageView as a splash screen. Now I want to blink ImageView image as a splash screen. This is my splash screen
Solution 1:
The following code snippet will blink the ImageView . Set the background of ImageView as Transparent.
Animationanimation=newAlphaAnimation(1, 0); //to change visibility from visible to invisible
animation.setDuration(1000); //1 second duration for each animation cycle
animation.setInterpolator(newLinearInterpolator());
animation.setRepeatCount(Animation.INFINITE); //repeating indefinitely
animation.setRepeatMode(Animation.REVERSE); //animation will start from end point once ended.
imageButton.startAnimation(animation); //to start animation
Solution 2:
**Try this code **
image = (ImageView) findViewById(R.id.image);
Animationanimation=newAlphaAnimation((float) 0.5, 0); // Change alpha from fully visible to invisible
animation.setDuration(500); // duration - half a second
animation.setInterpolator(newLinearInterpolator()); // do not alter// animation// rate
animation.setRepeatCount(Animation.INFINITE); // Repeat animation// infinitely
animation.setRepeatMode(Animation.REVERSE); // Reverse animation at the// end so the button will// fade back in
image.startAnimation(animation);
Solution 3:
If you don't want to blink the background of an ImageView (only blink the source image) or you just don't want to write any of that code yourself - which is exactly what I was trying to avoid - then you'll have to create a custom View and do it internally. Sure, there is a workaround with a parent FrameLayout, but let's not create more hierarchy when there is no real need. :)
Anyway, I actually wrote a Blinker View
because I was in need of such behavior, and you're free to use it from here: https://github.com/milosmns/blinking-image-view
Happy coding!
Post a Comment for "How To Blink Image In Imageview (android)"