声明:只做收集,并非原创
-
<h3>缩放动画</h3>
@NonNull
private AnimationSet getAnimationSet() {
AnimationSet set = new AnimationSet(true);
AlphaAnimation alphaAnim = new AlphaAnimation(0.5f, 1.0f);
set.addAnimation(alphaAnim);ScaleAnimation scaleAnim = new ScaleAnimation(1.0f, 1.5f, 1.0f, 1.5f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); set.addAnimation(scaleAnim); set.setFillAfter(true); set.setDuration(2500); set.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { //这里是动画的监听 } @Override public void onAnimationRepeat(Animation animation) { } }); return set;
}
直接view.startAnimation(set)
AnimationSet set = getAnimationSet();
findViewById(R.id.splash).startAnimation(set);
-
向四周伸张,直到完成显示
@SuppressLint("NewApi") public static void showAsCircular(View myView, float startRadius, long durationMills) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) { myView.setVisibility(View.VISIBLE); return; } int cx = (myView.getLeft() + myView.getRight()) / 2; int cy = (myView.getTop() + myView.getBottom()) / 2; int w = myView.getWidth(); int h = myView.getHeight(); // 勾股定理 & 进一法 int finalRadius = (int) Math.sqrt(w * w + h * h) + 1; Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, startRadius, finalRadius); myView.setVisibility(View.VISIBLE); anim.setDuration(durationMills); anim.start(); }
调用:
public static final long PERFECT_MILLS = 618;
public static final int MINI_RADIUS = 0;
showAsCircular(myView, MINI_RADIUS, PERFECT_MILLS);
-
由满向中间收缩,直到隐藏
@SuppressLint("NewApi")
public static void hideAsCircular(final View myView, float endRadius, long durationMills) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
myView.setVisibility(View.INVISIBLE);
return;
}int cx = (myView.getLeft() + myView.getRight()) / 2; int cy = (myView.getTop() + myView.getBottom()) / 2; int w = myView.getWidth(); int h = myView.getHeight(); // 勾股定理 & 进一法 int initialRadius = (int) Math.sqrt(w * w + h * h) + 1; Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, initialRadius, endRadius); anim.setDuration(durationMills); anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); myView.setVisibility(View.INVISIBLE); } }); anim.start(); }
调用:
hideAsCircular(myView, MINI_RADIUS, PERFECT_MILLS);
效果: