动画呼吸效果

呼吸效果的拦截器

public class BreatheInterpolator implements TimeInterpolator {  
    @Override  
    public float getInterpolation(float input) {  
  
        float x = 6 * input;  
        float k = 1.0f / 3;  
        int t = 6;  
        int n = 1;//控制函数周期,这里取此函数的第一个周期  
        float PI = 3.1416f;  
        float output = 0;  
  
        if (x >= ((n - 1) * t) && x < ((n - (1 - k)) * t)) {  
            output = (float) (0.5 * Math.sin((PI / (k * t)) * ((x - k * t / 2) - (n - 1) * t)) + 0.5);  
  
        } else if (x >= (n - (1 - k)) * t && x < n * t) {  
            output = (float) Math.pow((0.5 * Math.sin((PI / ((1 - k) * t)) * ((x - (3 - k) * t / 2) - (n - 1) * t)) + 0.5), 2);  
        }  
        return output;  
    }  
}  
 private void startAlphaBreathAnimation() {  
      ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(tvShowBreathing, "alpha", 0f, 1f);  
      alphaAnimator.setDuration(4000);  
      alphaAnimator.setInterpolator(new BreatheInterpolator());//使用自定义的插值器  
      alphaAnimator.setRepeatCount(ValueAnimator.INFINITE);  
      alphaAnimator.start();  
  }  

你可能感兴趣的:(动画呼吸效果)