首页 > 解决方案 > ObjectAnimator 之后的 AnimationDrawable 导致错误

问题描述

我试图在一个活动中发生两个动画,第一个动画首先发生,只有在完成后,第二个动画才会开始。ObjectAnimator 使用 .ofFloat() 方法将 imageView 在屏幕上向上移动,然后我想要一个加载动画,该动画循环遍历多个图像文件以创建类似加载的效果。

这是我的代码:

        //Animations
        final Handler handler = new Handler(Looper.getMainLooper());
        handler.postDelayed(new Runnable()
        {
            @Override
            public void run()
            {
                //Change cloud from sleeping to awake/happy
                g2ndSleepingClouds.setBackgroundResource(R.drawable.clouds_happy_formatted);

                //Move image view 250 pixels up the screen vertically
                ObjectAnimator animation1 = ObjectAnimator.ofFloat(g2ndSleepingClouds, "translationY", -250f);
                animation1.setDuration(1000);
                animation1.start();

                //Loading animation
                loadingImageView.setBackgroundResource(R.drawable.loading_1);
                loadingAnimation = (AnimationDrawable) loadingImageView.getBackground();
                loadingAnimation.stop();
                loadingAnimation.start();

            }
        }, 1000);

我在 Logcat 中得到的错误是:

“android.graphics.drawable.BitmapDrawable 不能转换为 android.graphics.drawable.AnimationDrawable”

有什么帮助吗?

标签: javaandroidandroid-studio

解决方案


推荐阅读