android - nineoldAndroid AnimationListenerAdapter

标签 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
)
    }

我使用了 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/

相关文章:

android - Play 商店显示 "This app is not compatible with any of your devices"

android - Jetpack 撰写 : How to draw shaped border?

安卓蓝牙服务名称

android - 如何将动画添加到 BottomSheetDialogFragment

java - 理解 "Sprite' s onDraw()"方法时遇到问题

android - 我的 Android Studio 安装了什么版本的支持库

java - 服务中的 Android BroadcastReceiver 在向其发送广播时给出空指针异常

android - 更改抽屉导航的过渡

java - 使用相对路径添加 Android jar 文件

android - Android 库项目中的 Multidex?