XML is as follows:
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:repeatCount="infinite" android:repeatMode="restart"> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="1000"/> <alpha android:startOffset="3000" android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="1000"/></set>
The function originally intended to be implemented is to make the transparency from 0 to 1, wait for 2 seconds, and then let the transparency from 1 to 0 to achieve the goal of flashing; the advantage of doing so is that you can control the display time;
Some people say that setrepeatcount (animation. infinite); you can do it. It is best to set the animationlistener to repeat the onanimationend event.
Animation anim = AnimationUtils.loadAnimation(BuzzFinderActivity.this, R.anim.crosshair_focusing); anim.setAnimationListener(new AnimationListener() { @Override public void onAnimationEnd(Animation arg0) { Animation anim = AnimationUtils.loadAnimation(BuzzFinderActivity.this, R.anim.crosshair_focusing); anim.setAnimationListener(this); brackets.startAnimation(anim); } @Override public void onAnimationRepeat(Animation arg0) { // TODO Auto-generated method stub } @Override public void onAnimationStart(Animation arg0) { // TODO Auto-generated method stub } });
Certificate -------------------------------------------------------------------------------------------------------------------------------------
Digress:
Although only the Alpha animation is used, the following settings can also achieve the flickering effect, but the display time is not well controlled. If you want to make the time of the gradient inconsistent, it will be even worse.
Alpha. setrepeatcount (animation. Infinite );
Alpha. setrepeatmode (animation. Reverse );
Certificate -------------------------------------------------------------------------------------------------------------------------------------
Discussion: http://stackoverflow.com/questions/4480652/android-animation-does-not-repeat