Skip to content

Instantly share code, notes, and snippets.

@cesarferreira
Created May 27, 2014 13:58
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cesarferreira/4fcae632b18904035d3b to your computer and use it in GitHub Desktop.
Save cesarferreira/4fcae632b18904035d3b to your computer and use it in GitHub Desktop.
Make a View Blink for a desired duration (android)
// Animate a text view
TextView myText = (TextView) findViewById(R.id.textView1);
myText = (TextView)Utils.makeMeBlink(myText,250,20);
// Animate an image view
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView = (ImageView)Utils.makeMeBlink(imageView,250,20);
/**
* Make a View Blink for a desired duration
*
* @param view view that will be animated
* @param duration for how long in ms will it blink
* @param offset start offset of the animation
* @return returns the same view with animation properties
*/
public static View makeMeBlink(View view, int duration, int offset) {
Animation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(duration);
anim.setStartOffset(offset);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
view.startAnimation(anim);
return view;
}
@mohan55
Copy link

mohan55 commented Sep 15, 2015

where can i find Utils class... can u add it..?

@ahmadalibaloch
Copy link

Thank you Cesar

@engr-erum
Copy link

Hi ,
will it hide textview and remove animation after time interval ?

@fukemy
Copy link

fukemy commented May 10, 2021

then how to stop blink? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment