我在我的代码中使用了 android.animation.AnimatorListenerAdapter 类来收听动画。 示例:
downView.animate().translationX(-mViewWidth).setDuration(mAnimationTime).
setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(
Animator animation) {
boolean real_dismiss = true;
performDismiss(
//some code
)
}
我使用了 nineoldandroids 的向后兼容性库,动画工作正常,但我收到以下错误,它不允许我在我的监听器上运行我的代码:
ViewPropertyAnimator 类型中的方法 setListener(Animator.AnimatorListener) 不适用于参数 (new AnimatorListenerAdapter(){})
当我使用 API 级别 11 时,代码运行良好。 我的旧导入语句:
//import android.animation.Animator;
//import android.animation.AnimatorListenerAdapter;
//import android.animation.ValueAnimator;
我的新导入语句:
import com.nineoldandroids.animation.*;
import com.nineoldandroids.*;
最佳答案
我刚遇到同样的问题,找到了Jake Wharton's implementation SwipeDismissListener
的:
在第 156 行,Jake 使用 com.nineoldandroids.view.ViewPropertyAnimator.animate(View arg0)
执行相同的功能。
因此,您只需将代码更改为如下所示:
animate(downView)
.translationX(-mViewWidth)
.setDuration(mAnimationTime)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
boolean real_dismiss = true;
performDismiss(//some code)
}
而且应该不会有任何错误。
关于android - nineoldAndroid AnimationListenerAdapter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15628091/