下面列出了怎么用android.view.animation.AnimationSet的API类实例代码及写法,或者点击链接到github查看源代码。
void display(float x, float y) {
this.startPositionX = x;
this.startPositionY = y;
recordButtonFab.setVisibility(View.VISIBLE);
AnimationSet animation = new AnimationSet(true);
animation.addAnimation(new TranslateAnimation(Animation.ABSOLUTE, 0,
Animation.ABSOLUTE, 0,
Animation.ABSOLUTE, 0,
Animation.ABSOLUTE, 0));
animation.addAnimation(new ScaleAnimation(.5f, 1f, .5f, 1f,
Animation.RELATIVE_TO_SELF, .5f,
Animation.RELATIVE_TO_SELF, .5f));
animation.setDuration(ANIMATION_DURATION);
animation.setInterpolator(new OvershootInterpolator());
recordButtonFab.startAnimation(animation);
}
private void setOutAnimation(float[] direction, Interpolator interpolator, long duration) {
Animation push = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, direction[0], Animation.RELATIVE_TO_PARENT, direction[1],
Animation.RELATIVE_TO_PARENT, direction[2], Animation.RELATIVE_TO_PARENT, direction[3]
);
push.setInterpolator(interpolator);
push.setDuration(duration);
Animation fade = new AlphaAnimation(1, 0);
fade.setDuration(duration);
fade.setInterpolator(interpolator);
AnimationSet set = new AnimationSet(false);
set.addAnimation(push);
set.addAnimation(fade);
outAnimation = set;
}
private void calculateProgress(float value) {
if (value > 0){
if (value >= maxValue)
value = maxValue;
currentValue = value;
float currentAngle = (360 / maxValue) * value;
currentAngle += 270;
float aa = (currentAngle - 270);
LoaderAngleAnimation angleAnimation = new LoaderAngleAnimation(this, aa);
angleAnimation.setDuration(300);
LoaderTextAnimation textAnimation = new LoaderTextAnimation(this);
textAnimation.setDuration(300);
AnimationSet animationSet = new AnimationSet(false);
animationSet.addAnimation(angleAnimation);
animationSet.addAnimation(textAnimation);
this.startAnimation(animationSet);
}
}
private AnimationSet hideAllViews() {
if (mContinueIcon.getVisibility() == View.VISIBLE) {
hideContinueIconAnimations();
}
int HIDE_VIEW_ANIMATION_DURATION = 550;
hideViewAnimation(mGearIcon, HIDE_VIEW_ANIMATION_DURATION);
hideViewAnimation(mLoginTextLineOne, HIDE_VIEW_ANIMATION_DURATION);
if (mSuccessMessage.getVisibility() != View.INVISIBLE) {
hideViewAnimation(mSuccessMessage, HIDE_VIEW_ANIMATION_DURATION);
}
if (mSuccessIcon.getVisibility() != View.INVISIBLE) {
hideViewAnimation(mSuccessIcon, HIDE_VIEW_ANIMATION_DURATION);
hideViewAnimation(mSuccessCircle, HIDE_VIEW_ANIMATION_DURATION);
hideViewAnimation(mSuccessCircleShadow, HIDE_VIEW_ANIMATION_DURATION);
}
return hideViewAnimation(mLoginTextLineTwo, HIDE_VIEW_ANIMATION_DURATION);
}
/**
* 为话题提示VIew绑定动画</br>
*/
private void startAnimationForTopicTipView() {
int timePiece = 500;
int repeatCount = 4;
int startDeny = 50;
TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, 10, 0);
translateAnimation.setRepeatMode(Animation.REVERSE);
// translateAnimation.setStartOffset(startDeny * repeatCount+timePiece);
translateAnimation.setRepeatCount(Integer.MAX_VALUE);
translateAnimation.setDuration(timePiece);
AlphaAnimation alphaAnimationIn = new AlphaAnimation(0, 1.0f);
alphaAnimationIn.setDuration(timePiece);
alphaAnimationIn.setStartOffset(startDeny * repeatCount);
AnimationSet animationSet = new AnimationSet(true);
animationSet.addAnimation(alphaAnimationIn);
animationSet.addAnimation(translateAnimation);
// animationSet.addAnimation(alphaAnimationOut);
// animationSet.setFillAfter(true);
mTopicTipView.startAnimation(animationSet);
}
public static void setAdapterInsertAnimation(final View aCard, int row, int height) {
final int ANIMATION_DURATION = 650;
final int BASE_DELAY = 50;
TranslateAnimation translationAnimation = new TranslateAnimation(0, 0, height, 0);
AlphaAnimation alphaAnimation = new AlphaAnimation(0f, 1f);
final AnimationSet animationSet = new AnimationSet(true);
animationSet.addAnimation(translationAnimation);
animationSet.addAnimation(alphaAnimation);
animationSet.setInterpolator(new AccelerateDecelerateInterpolator());
animationSet.setFillAfter(true);
animationSet.setFillBefore(true);
animationSet.setDuration(ANIMATION_DURATION + row * BASE_DELAY);
aCard.setAnimation(animationSet);
}
/**
* 中间的View动画播放
*/
private void playCenter() {
AnimationSet animationSet = new AnimationSet(false);
ScaleAnimation scaleSmall = new ScaleAnimation(1.0f, 0.6f, 1.0f, 0.6f,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
ScaleAnimation scaleBig = new ScaleAnimation(1.0f, 5.0f/3, 1.0f, 5.0f/3,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleBig.setDuration(2*1000);
scaleBig.setInterpolator(interpolator);
scaleSmall.setDuration(2*1000);
scaleSmall.setStartOffset(2*1000);
scaleSmall.setRepeatCount(-1);
scaleSmall.setFillEnabled(true);
scaleSmall.setFillAfter(true);
scaleBig.setStartOffset(2*1000);
scaleBig.setRepeatCount(-1);
scaleBig.setFillEnabled(true);
scaleBig.setFillAfter(true);
scaleSmall.setInterpolator(interpolator);
animationSet.addAnimation(scaleBig);
animationSet.addAnimation(scaleSmall);
center.startAnimation(animationSet);
}
/**
* For the Activity Circle Icon and text
*/
public static void startAlphaRevealAnimation(final View VIEW) {
final int ANIMATION_DURATION = 1000;
final Animation mShowViewAnimation = new AlphaAnimation(0f, 1f);
mShowViewAnimation.setDuration(ANIMATION_DURATION);
AnimationSet mAnimations = new AnimationSet(true);
mAnimations.setInterpolator(new AccelerateDecelerateInterpolator());
mAnimations.addAnimation(mShowViewAnimation);
mAnimations.setFillAfter(true);
if (VIEW != null)
VIEW.startAnimation(mAnimations);
}
private void animateDragged() {
if (mLastDragged >= 0) {
final View v = getChildAt(mLastDragged);
final Rect r = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
r.inset(-r.width() / 20, -r.height() / 20);
v.measure(MeasureSpec.makeMeasureSpec(r.width(), MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(r.height(), MeasureSpec.EXACTLY));
v.layout(r.left, r.top, r.right, r.bottom);
AnimationSet animSet = new AnimationSet(true);
ScaleAnimation scale = new ScaleAnimation(0.9091f, 1, 0.9091f, 1, v.getWidth() / 2, v.getHeight() / 2);
scale.setDuration(ANIMATION_DURATION);
AlphaAnimation alpha = new AlphaAnimation(1, .5f);
alpha.setDuration(ANIMATION_DURATION);
animSet.addAnimation(scale);
animSet.addAnimation(alpha);
animSet.setFillEnabled(true);
animSet.setFillAfter(true);
v.clearAnimation();
v.startAnimation(animSet);
}
}
public void display(float x) {
this.startPositionX = x;
this.lastPositionX = x;
recordButtonFab.setVisibility(View.VISIBLE);
AnimationSet animation = new AnimationSet(true);
animation.addAnimation(new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, -.25f,
Animation.RELATIVE_TO_SELF, -.25f));
animation.addAnimation(new ScaleAnimation(.5f, 1f, .5f, 1f,
Animation.RELATIVE_TO_SELF, .5f,
Animation.RELATIVE_TO_SELF, .5f));
animation.setFillBefore(true);
animation.setFillAfter(true);
animation.setDuration(ANIMATION_DURATION);
animation.setInterpolator(new OvershootInterpolator());
recordButtonFab.startAnimation(animation);
}
private void startAnimation() {
AnimationSet animationSet = new AnimationSet(true);
RotateAnimation rotateAnimation = new RotateAnimation(0, 360,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
ScaleAnimation scaleAnimation = new ScaleAnimation(1.5f, 1, 1.5f, 1,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
animationSet.addAnimation(rotateAnimation);
animationSet.addAnimation(scaleAnimation);
animationSet.addAnimation(alphaAnimation);
animationSet.setDuration(2000);
mAboutInfo.startAnimation(animationSet);
}
public ListenableFuture<Void> hide(float x) {
final SettableFuture<Void> future = new SettableFuture<>();
float offset = getOffset(x);
AnimationSet animation = new AnimationSet(true);
animation.addAnimation(new TranslateAnimation(Animation.ABSOLUTE, offset,
Animation.ABSOLUTE, 0,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0));
animation.addAnimation(new AlphaAnimation(1, 0));
animation.setDuration(MicrophoneRecorderView.ANIMATION_DURATION);
animation.setFillBefore(true);
animation.setFillAfter(false);
slideToCancelView.postDelayed(() -> future.set(null), MicrophoneRecorderView.ANIMATION_DURATION);
slideToCancelView.setVisibility(View.GONE);
slideToCancelView.startAnimation(animation);
return future;
}
public void startAnimate(int count)
{
Animation fadeIn = new AlphaAnimation(0.2f, 1f);
fadeIn.setInterpolator(new DecelerateInterpolator()); //add this
fadeIn.setDuration(1000);
Animation fadeOut = new AlphaAnimation(1f, 0.2f);
fadeOut.setInterpolator(new AccelerateInterpolator()); //and this
fadeOut.setStartOffset(1000);
fadeOut.setDuration(1000);
final AnimationSet animationSet = new AnimationSet(false);
animationSet.addAnimation(fadeIn);
animationSet.addAnimation(fadeOut);
animationSet.setRepeatCount(count);
animationSet.setRepeatMode(Animation.REVERSE);
setAnimation(animationSet);
animationSet.start();
}
private Animation getAnimationSet(boolean fromXML) {
if (fromXML) {
Animation animation = AnimationUtils.loadAnimation(this, R.anim.view_animation);
return animation;
} else {
AnimationSet innerAnimationSet = new AnimationSet(true);
innerAnimationSet.setInterpolator(new BounceInterpolator());
innerAnimationSet.setStartOffset(1000);
innerAnimationSet.addAnimation(getScaleAnimation());
innerAnimationSet.addAnimation(getTranslateAnimation());
AnimationSet animationSet = new AnimationSet(true);
animationSet.setInterpolator(new LinearInterpolator());
animationSet.addAnimation(getAlphaAnimation());
animationSet.addAnimation(getRotateAnimation());
animationSet.addAnimation(innerAnimationSet);
return animationSet;
}
}
private AnimationSet getEntryAnimation(int inAnimationDuration) {
//In
AnimationSet mInAnimationSet = new AnimationSet(false);
TranslateAnimation mSlideInAnimation = new TranslateAnimation(
TranslateAnimation.RELATIVE_TO_PARENT, 0.0f,
TranslateAnimation.RELATIVE_TO_PARENT, 0.0f,
TranslateAnimation.RELATIVE_TO_SELF, -1.0f,
TranslateAnimation.RELATIVE_TO_SELF, 0.0f);
mSlideInAnimation.setFillAfter(true);
AlphaAnimation mFadeInAnimation = new AlphaAnimation(0.0f, 1.0f);
mFadeInAnimation.setFillAfter(true);
mInAnimationSet.addAnimation(mSlideInAnimation);
mInAnimationSet.addAnimation(mFadeInAnimation);
mInAnimationSet.setDuration(inAnimationDuration);
return mInAnimationSet;
}
/**
* 收缩动画
*/
private static Animation createShrinkAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta, long startOffset, long duration, Interpolator interpolator) {
AnimationSet animationSet = new AnimationSet(false);
animationSet.setFillAfter(true);
//收缩过程中,child 逆时针自旋转360度
final long preDuration = duration / 2;
Animation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setStartOffset(startOffset);
rotateAnimation.setDuration(preDuration);
rotateAnimation.setInterpolator(new LinearInterpolator());
rotateAnimation.setFillAfter(true);
animationSet.addAnimation(rotateAnimation);
//收缩过程中位移,并逆时针旋转360度
Animation translateAnimation = new RotateAndTranslateAnimation(0, toXDelta, 0, toYDelta, 360, 720);
translateAnimation.setStartOffset(startOffset + preDuration);
translateAnimation.setDuration(duration - preDuration);
translateAnimation.setInterpolator(interpolator);
translateAnimation.setFillAfter(true);
animationSet.addAnimation(translateAnimation);
return animationSet;
}
/**
* 创建动画 平移动画直接传递偏移量
*
* @param startX
* @param startY
* @return
*/
private Animation createAnim(int startX, int startY) {
int[] des = new int[2];
imgCart.getLocationInWindow(des);
AnimationSet set = new AnimationSet(false);
Animation translationX = new TranslateAnimation(0, des[0] - startX, 0, 0);
translationX.setInterpolator(new LinearInterpolator());
Animation translationY = new TranslateAnimation(0, 0, 0, des[1] - startY);
translationY.setInterpolator(new AccelerateInterpolator());
Animation alpha = new AlphaAnimation(1, 0.5f);
set.addAnimation(translationX);
set.addAnimation(translationY);
set.addAnimation(alpha);
set.setDuration(500);
return set;
}
/**
* 显示减号的动画
*/
private Animation getShowAnimation() {
AnimationSet set = new AnimationSet(true);
RotateAnimation rotate = new RotateAnimation(0, 720, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
set.addAnimation(rotate);
TranslateAnimation translate = new TranslateAnimation(
TranslateAnimation.RELATIVE_TO_SELF, 2f
, TranslateAnimation.RELATIVE_TO_SELF, 0
, TranslateAnimation.RELATIVE_TO_SELF, 0
, TranslateAnimation.RELATIVE_TO_SELF, 0);
set.addAnimation(translate);
AlphaAnimation alpha = new AlphaAnimation(0, 1);
set.addAnimation(alpha);
set.setDuration(500);
return set;
}
/**
* 隐藏减号的动画
*/
private Animation getHiddenAnimation() {
AnimationSet set = new AnimationSet(true);
RotateAnimation rotate = new RotateAnimation(0, 720, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
set.addAnimation(rotate);
TranslateAnimation translate = new TranslateAnimation(
TranslateAnimation.RELATIVE_TO_SELF, 0
, TranslateAnimation.RELATIVE_TO_SELF, 2f
, TranslateAnimation.RELATIVE_TO_SELF, 0
, TranslateAnimation.RELATIVE_TO_SELF, 0);
set.addAnimation(translate);
AlphaAnimation alpha = new AlphaAnimation(1, 0);
set.addAnimation(alpha);
set.setDuration(500);
return set;
}
/**
* Assign a "scale to 120% and back bounce + fade out and in" animation to the given view
* @param view the view to animate
* @param duration duration of the animation
*/
public static void setBounceAnimatiom(View view, long duration){
ScaleAnimation grow = new ScaleAnimation(1.0f, 1.2f, 1.0f, 1.2f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
grow.setDuration(duration);
ScaleAnimation shrink = new ScaleAnimation(1.0f, 0.8f, 1.0f, 0.8f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
shrink.setDuration(duration);
shrink.setStartOffset(duration);
// Fade out then repeat to fade back in
AlphaAnimation fadeOut = new AlphaAnimation(1.0f, 0.3f);
fadeOut.setInterpolator(new DecelerateInterpolator()); //and this
fadeOut.setDuration(100);
fadeOut.setRepeatMode(Animation.REVERSE);
fadeOut.setRepeatCount(1);
AnimationSet set = new AnimationSet(false);
set.addAnimation(grow);
set.addAnimation(shrink);
set.addAnimation(fadeOut);
view.startAnimation(set);
}
/**
* 进入动画
*
* @param context
* @param fromYDelta
* @return
*/
private void createInAnimation(Context context, int fromYDelta) {
try {
AnimationSet set = new AnimationSet(context, null);
set.setFillAfter(true);
TranslateAnimation animation = new TranslateAnimation(0, 0, fromYDelta, 0);
animation.setDuration(ANIMATION_TIME);
set.addAnimation(animation);
if (mFrameLayout != null) {
mRootView.setAnimation(set);
AnimationSet setAlpha = new AnimationSet(mContext, null);
setAlpha.setFillAfter(true);
AlphaAnimation alphaAnimation = new AlphaAnimation(0f, 1f);
alphaAnimation.setDuration(ANIMATION_TIME);
setAlpha.addAnimation(alphaAnimation);
mFrameLayout.startAnimation(setAlpha);
} else {
mRootView.startAnimation(set);
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Start Loop animation on given list of characters
*/
public long applyLoopAnimation(List<TextView> targetList) {
long duration = (long) (CHARACTER_ANIM_DURATION * 5f);
for (final TextView target : targetList) {
AnimationSet set = new AnimationSet(true);
if (headerLoopAnim == HeaderLoopAnim.ZOOM) {
addLoopScaleAnimations(duration, set);
} else if (headerLoopAnim == HeaderLoopAnim.FADE) {
addLoopFadeAnimations(duration, set);
}
target.startAnimation(set);
}
// loop anim iteration
currentLoopIteration = (currentLoopIteration + 1) % headerLoopAnimIteration;
return (long) ((duration * 2.1f) + 300);
}
/**
* 初始化动画集
* @return
*/
private AnimationSet initAnimationSet() {
AnimationSet as = new AnimationSet(true);
//缩放度:变大两倍
ScaleAnimation sa = new ScaleAnimation(1f, 2f, 1f, 2f,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
sa.setDuration(show_spacing_time * 3);
sa.setRepeatCount(Animation.INFINITE);// 设置循环
//透明度
AlphaAnimation aa = new AlphaAnimation(1, 0.1f);
aa.setDuration(show_spacing_time * 3);
aa.setRepeatCount(Animation.INFINITE);//设置循环
as.addAnimation(sa);
as.addAnimation(aa);
return as;
}
private static Animation createShrinkAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta,
long startOffset, long duration, Interpolator interpolator) {
AnimationSet animationSet = new AnimationSet(false);
animationSet.setFillAfter(true);
final long preDuration = duration / 2;
Animation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setStartOffset(startOffset);
rotateAnimation.setDuration(preDuration);
rotateAnimation.setInterpolator(new LinearInterpolator());
rotateAnimation.setFillAfter(true);
animationSet.addAnimation(rotateAnimation);
Animation translateAnimation = new RotateAndTranslateAnimation(0, toXDelta, 0, toYDelta, 360, 720);
translateAnimation.setStartOffset(startOffset + preDuration);
translateAnimation.setDuration(duration - preDuration);
translateAnimation.setInterpolator(interpolator);
translateAnimation.setFillAfter(true);
animationSet.addAnimation(translateAnimation);
return animationSet;
}
public static void shakeCurtain(View v) {
AnimationSet set = new AnimationSet(false);
Animation anim1 = getTranslateAnimation(0, 0, 0, -200, 110);
Animation anim2 = getTranslateAnimation(0, 0, -200, 0, 80);
Animation anim3 = getTranslateAnimation(0, 0, 0, -50, 25);
Animation anim4 = getTranslateAnimation(0, 0, -50, 0, 25);
anim1.setStartOffset(20);
anim2.setStartOffset(230);
anim3.setStartOffset(360);
anim4.setStartOffset(400);
set.addAnimation(anim1);
set.addAnimation(anim2);
set.addAnimation(anim3);
set.addAnimation(anim4);
v.startAnimation(set);
}
private AnimationSet startShowContinueIconAnimations() {
Animation mScaleAnimation = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
Animation mRotateAnimation = new RotateAnimation(
0, 360,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f
);
mRotateAnimation.setRepeatCount(0);
AnimationSet mAnimations = new AnimationSet(true);
mAnimations.setDuration(REVEAL_ANIMATION_DURATION);
mAnimations.setFillAfter(true);
mAnimations.setInterpolator(new OvershootInterpolator(1.5f));
mAnimations.addAnimation(mScaleAnimation);
mAnimations.addAnimation(mRotateAnimation);
mContinueIcon.startAnimation(mAnimations);
return mAnimations;
}
private AnimationSet showSuccessAnimation() {
Log.d(LOG_TAG, "Showing Success Animation");
mSuccessMessage.setText(
getResources().getString(R.string.login_on_success_message, new Settings(getBaseContext()).getGeneralTwitchDisplayName())
);
final AnimationSet mCircleShadowAnimations = getSuccessShadowAnimation();
final AnimationSet mCircleAnimations = getSuccessCircleAnimation();
final AnimationSet mIconAnimations = getSuccessIconAnimation();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mSuccessCircleShadow.startAnimation(mCircleShadowAnimations);
mSuccessIcon.startAnimation(mIconAnimations);
showTextLineAnimations(mSuccessMessage, 1);
}
}, 150);
mSuccessCircle.startAnimation(mCircleAnimations);
hideContinueIconAnimations();
hideViewAnimation(mLoginTextContainer, HIDE_INSTRUCTIONS_DURATION);
return mCircleAnimations;
}
public static void setAdapterInsertAnimation(final View aCard, int row, int height) {
final int ANIMATION_DURATION = 650;
final int BASE_DELAY = 50;
TranslateAnimation translationAnimation = new TranslateAnimation(0,0, height,0);
AlphaAnimation alphaAnimation = new AlphaAnimation(0f, 1f);
final AnimationSet animationSet = new AnimationSet(true);
animationSet.addAnimation(translationAnimation);
animationSet.addAnimation(alphaAnimation);
animationSet.setInterpolator(new AccelerateDecelerateInterpolator());
animationSet.setFillAfter(true);
animationSet.setFillBefore(true);
animationSet.setDuration(ANIMATION_DURATION + row * BASE_DELAY);
aCard.setAnimation(animationSet);
}
public static void postScaleAnimation(View v) {
ScaleAnimation scaleAnimation1 = new ScaleAnimation(1.0f, 0.5f, 1.0f, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation1.setDuration(200);
ScaleAnimation scaleAnimation2 = new ScaleAnimation(0.5f, 1.5f, 0.5f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation2.setDuration(100);
AnimationSet set = new AnimationSet(true);
set.addAnimation(scaleAnimation1);
set.addAnimation(scaleAnimation2);
v.startAnimation(set);
}
@MainThread
public void append(int value) {
if (index >= codes.size()) return;
setInactive(containers);
setActive(containers.get(index));
TextView codeView = codes.get(index++);
Animation translateIn = new TranslateAnimation(0, 0, codeView.getHeight(), 0);
translateIn.setInterpolator(new OvershootInterpolator());
translateIn.setDuration(500);
Animation fadeIn = new AlphaAnimation(0, 1);
fadeIn.setDuration(200);
AnimationSet animationSet = new AnimationSet(false);
animationSet.addAnimation(fadeIn);
animationSet.addAnimation(translateIn);
animationSet.reset();
animationSet.setStartTime(0);
codeView.setText(String.valueOf(value));
codeView.clearAnimation();
codeView.startAnimation(animationSet);
if (index == codes.size() && listener != null) {
listener.onCodeComplete(Stream.of(codes).map(TextView::getText).collect(Collectors.joining()));
}
}