//接到需求密码不对时,textView 左右浮动,ObjectAnimator 直接创建匿名内部类Animator.AnimatorListener,会报以下错误,程序崩溃 public void floatTextView(TextView view){ view.setVisibility(View.VISIBLE); ObjectAnimator animator = ObjectAnimator.ofFloat(view, "translationX", 0, 50, -50, 0); animator.setDuration(1000); animator.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { view.setVisibility(View.INVISIBLE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); animator.start(); }
//同事给出的解决方法:换一个方式、新建一个类继承Animator.AnimatorListener
public class AnimatorLister implements Animator.AnimatorListener { public void setTextView(TextView textView) { this.textView = textView; } private TextView textView; @Override public void onAnimationStart(Animator animation, boolean isReverse) { } @Override public void onAnimationEnd(Animator animation, boolean isReverse) { textView.setVisibility(View.INVISIBLE); } @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }
public void floatTextView(TextView view){ view.setVisibility(View.VISIBLE); ObjectAnimator animator = ObjectAnimator.ofFloat(view, "translationX", 0, 50, -50, 0); animator.setDuration(1000); AnimatorLister animatorLister=new AnimatorLister(); animatorLister.setTextView(view); animator.addListener(animatorLister); animator.start(); }
标签:lang,java,animator,void,animation,Override,AnimatorListener,public,Animator From: https://www.cnblogs.com/mhzf/p/17075104.html