0

Could anyone help me how to use RotateDrawable in Xamarin? I am working on a Xamarin.Forms project and I need to rotate a drawable in the MainActivity.cs and then set the rotated drawable as a background, I've wrote this but I got an exception:

RotateDrawable rotateDrawable = (RotateDrawable)Resource.Drawable.ts_logo; <<<< got exception here
Android.Animation.ObjectAnimator.OfInt(rotateDrawable, "level", 0, 10000).Start();
Window.DecorView.SetBackground(rotateDrawable);

The exception message is "System.InvalidCastException: Specified cast is not valid"

Top Systems
  • 951
  • 12
  • 24

1 Answers1

0

According to your description and code, Resource.Drawable.ts_logo is ID, you can not convert it to RotateDrawable.

You can try the following code:

RotateDrawable rotateDrawable = new RotateDrawable();
        rotateDrawable.Drawable = GetDrawable(Resource.Drawable.a11);
        Android.Animation.ObjectAnimator.OfInt(rotateDrawable, "level", 0, 10000).Start();
        Window.DecorView.SetBackground(rotateDrawable);
Cherry Bu - MSFT
  • 10,160
  • 1
  • 10
  • 16