You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.8 KiB
76 lines
2.8 KiB
package net.micode.notes.ui;
|
|
|
|
import android.animation.ValueAnimator;
|
|
import android.view.animation.AccelerateDecelerateInterpolator;
|
|
import android.widget.TextView;
|
|
|
|
public class WaveAnimation {
|
|
|
|
// 整行文字从左到右淡入显示动画
|
|
public static void applyFadeInAnimation(TextView textView) {
|
|
// 设置初始状态为完全透明
|
|
textView.setAlpha(0f);
|
|
textView.setVisibility(android.view.View.VISIBLE);
|
|
|
|
// 创建透明度渐变动画
|
|
ValueAnimator fadeInAnimator = ValueAnimator.ofFloat(0f, 1f);
|
|
fadeInAnimator.setDuration(2000); // 2秒淡入效果
|
|
fadeInAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
|
|
|
|
fadeInAnimator.addUpdateListener(animation -> {
|
|
float alpha = (float) animation.getAnimatedValue();
|
|
textView.setAlpha(alpha);
|
|
});
|
|
|
|
// 创建从左到右的滑入效果
|
|
ValueAnimator slideInAnimator = ValueAnimator.ofFloat(-100f, 0f);
|
|
slideInAnimator.setDuration(1500); // 1.5秒滑入
|
|
slideInAnimator.setInterpolator(new android.view.animation.OvershootInterpolator());
|
|
|
|
slideInAnimator.addUpdateListener(animation -> {
|
|
float translationX = (float) animation.getAnimatedValue();
|
|
textView.setTranslationX(translationX);
|
|
});
|
|
|
|
// 同时启动两个动画
|
|
fadeInAnimator.start();
|
|
slideInAnimator.start();
|
|
}
|
|
|
|
// 从左到右逐字淡入效果(如果需要的话)
|
|
public static void applyCharByCharFadeIn(TextView textView) {
|
|
String text = textView.getText().toString();
|
|
int length = text.length();
|
|
|
|
// 设置初始状态
|
|
textView.setAlpha(0f);
|
|
textView.setVisibility(android.view.View.VISIBLE);
|
|
|
|
// 为整行文字创建统一的淡入动画
|
|
ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
|
|
animator.setDuration(2500); // 总时长2.5秒
|
|
animator.setInterpolator(new android.view.animation.DecelerateInterpolator());
|
|
|
|
animator.addUpdateListener(animation -> {
|
|
float progress = (float) animation.getAnimatedValue();
|
|
textView.setAlpha(progress);
|
|
|
|
// 添加轻微的缩放效果
|
|
float scale = 0.8f + (progress * 0.2f); // 从0.8倍放大到1倍
|
|
textView.setScaleX(scale);
|
|
textView.setScaleY(scale);
|
|
});
|
|
|
|
animator.start();
|
|
}
|
|
|
|
// 兼容旧版本的方法名 - 使用新的淡入效果
|
|
public static void applyComplexWaveAnimation(TextView textView) {
|
|
applyFadeInAnimation(textView);
|
|
}
|
|
|
|
// 兼容旧版本的另一个方法名
|
|
public static void applyCharWaveAnimation(TextView textView) {
|
|
applyCharByCharFadeIn(textView);
|
|
}
|
|
} |