谁能帮助我如何在Xamarin中使用RotateDrawable?我正在开发一个Xamarin.Forms项目,我需要在MainActivity.cs中旋转一个drawable,然后将旋转的drawable设置为背景,我写了这个,但我有一个例外:
RotateDrawable rotateDrawable = (RotateDrawable)Resource.Drawable.ts_logo; <<<< got exception here
Android.Animation.ObjectAnimator.OfInt(rotateDrawable, "level", 0, 10000).Start();
Window.DecorView.SetBackground(rotateDrawable);
异常消息是“System.InvalidCastException: Specified cast is not valid
”
根据您的描述和代码,Resource.Drawable.ts_logo是ID,您无法将其转换为RotateDrawable。
您可以尝试以下代码:
RotateDrawable rotateDrawable = new RotateDrawable();
rotateDrawable.Drawable = GetDrawable(Resource.Drawable.a11);
Android.Animation.ObjectAnimator.OfInt(rotateDrawable, "level", 0, 10000).Start();
Window.DecorView.SetBackground(rotateDrawable);