如何在Xamarin中使用RotateDrawable?

问题描述 投票:0回答:1

谁能帮助我如何在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

xamarin xamarin.forms xamarin.android
1个回答
0
投票

根据您的描述和代码,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);
© www.soinside.com 2019 - 2024. All rights reserved.