nineoldAndroid AnimationListenerAdapter

时间:2013-03-26 02:06:12

标签: android android-animation android-library android-compatibility

我在代码中使用了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
)
    }

我使用了九重级的后向兼容性lib,动画工作正常,但是我收到了以下错误,这不能让我在我的监听器上运行我的代码:

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.*;

1 个答案:

答案 0 :(得分:2)

我刚遇到同样的问题,发现了SwipeDismissListener的{​​{3}}:

在第156行,杰克正在使用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)
}

并且不应该有任何错误。