Home » Java » java – AnimationDrawable after ObjectAnimator causes error-Exceptionshub

java – AnimationDrawable after ObjectAnimator causes error-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I’m trying to have two animations occur in one activity with the first happening first and only once it’s done, does the second start. The ObjectAnimator moves the imageView up the screen using the .ofFloat() method and then I want a loading animation which loops through several image files to create a loading-like effect.

This is my code:

        //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);

The error I get in Logcat is:

“android.graphics.drawable.BitmapDrawable cannot be cast to android.graphics.drawable.AnimationDrawable”

Any help?

How to&Answers: