我正在尝试实施Blink动画。
此代码显示淡入淡出和淡出的视图:
AlphaAnimation blink = new AlphaAnimation(0.0f, 1.0f);
blink.setDuration(500);
blink.setStartOffset(0);
//changing it makes more than one animation appear in different time stamps.
blink.setRepeatMode(Animation.REVERSE);
blink.setRepeatCount(Animation.INFINITE);
我有两个问题:
答案 0 :(得分:4)
对于没有褪色的动画,您可以创建自己的自定义插值器:
import android.view.animation.Interpolator;
public class StepInterpolator implements Interpolator {
float mDutyCycle;
public StepInterpolator(float dutyCycle) {
mDutyCycle = dutyCycle;
}
@Override
public float getInterpolation(float input) {
return input < mDutyCycle ? 0 : 1;
}
}
然后在Animation对象中设置插值器:
blink.setInterpolator(new StepInterpolator(0.5f));
答案 1 :(得分:1)
所以,我的答案......这是一个在一定时间间隔内切换视图可见性的类。当然它可以用不同的方式解决,也许你会得到一些灵感......
public static class ViewBlinker {
private Handler handler = new Handler();
private Runnable blinker;
public ViewBlinker(final View v, final int interval) {
this.blinker = new Runnable() {
@Override
public void run() {
v.setVisibility(v.getVisibility()==View.VISIBLE?View.INVISIBLE:View.VISIBLE);
handler.postDelayed(blinker, interval);
}
};
}
public void startBlinking() {
handler.post(blinker);
}
public void stopBlinking() {
handler.removeCallbacks(blinker);
}
}
你可以这样使用它:
ViewBlinker blinker = new ViewBlinker(YOUR_BLINK_VIEW, YOUR_BLINK_INTERVAL);
blinker.startBlinking();
当视图完成闪烁时,请致电
blinker.stopBlinking();