弹出动画
/*
Copyright 2016 Tomer Goldstein
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.tomergoldst.tooltips;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.view.View;
import android.view.animation.AnticipateOvershootInterpolator;
import android.view.animation.OvershootInterpolator;
/**
* Created by Tomer on 18/06/2016.
*/
class AnimationUtils {
static ObjectAnimator popup(final View view, final long duration) {
view.setAlpha(0);
view.setVisibility(View.VISIBLE);
ObjectAnimator popup = ObjectAnimator.ofPropertyValuesHolder(view,
PropertyValuesHolder.ofFloat("alpha", 0f, 1f),
PropertyValuesHolder.ofFloat("scaleX", 0f, 1f),
PropertyValuesHolder.ofFloat("scaleY", 0f, 1f));
popup.setDuration(duration);
popup.setInterpolator(new OvershootInterpolator());
return popup;
}
static ObjectAnimator popout(final View view, final long duration, final AnimatorListenerAdapter animatorListenerAdapter) {
ObjectAnimator popout = ObjectAnimator.ofPropertyValuesHolder(view,
PropertyValuesHolder.ofFloat("alpha", 1f, 0f),
PropertyValuesHolder.ofFloat("scaleX", 1f, 0f),
PropertyValuesHolder.ofFloat("scaleY", 1f, 0f));
popout.setDuration(duration);
popout.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
view.setVisibility(View.GONE);
if (animatorListenerAdapter != null) {
animatorListenerAdapter.onAnimationEnd(animation);
}
}
});
popout.setInterpolator(new AnticipateOvershootInterpolator());
return popout;
}
}
本文介绍了一种基于Android平台的视图弹出动画实现方式,通过调整透明度(alpha)、水平缩放(scaleX)及垂直缩放(scaleY),创建了弹出(popup)与消失(popout)两种动画效果。

被折叠的 条评论
为什么被折叠?



