我想创建一个动画启动画面,但是我收到了这个错误:
Android.Content.Res.Resources + NotFoundException:File res / drawable / splash_screen.xml来自可绘制资源ID#0x7f0200bc
当我将Imageview的src更改为@ drawable / logo2时,我的代码有效,但后来我得到了静态splas屏幕。
[Activity(Theme = "@style/MyTheme", MainLauncher = true, NoHistory = true, ScreenOrientation = ScreenOrientation.Portrait)]
public class SplashActivity : Activity
{
static readonly string TAG = "X:" + typeof(SplashActivity).Name;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
}
protected override void OnResume()
{
base.OnResume();
Task startupWork = new Task(() =>
{
Task.Delay(5000); // Simulate a bit of startup work.
});
startupWork.ContinueWith(t =>
{
StartActivity(typeof(MainActivity));
}, TaskScheduler.FromCurrentSynchronizationContext());
startupWork.Start();
}
public override void OnWindowFocusChanged(bool hasFocus)
{
if (hasFocus)
{
ImageView imageView = FindViewById<ImageView>(Resource.Id.animated_android);
AnimationDrawable animation = (AnimationDrawable)imageView.Drawable;
animation.Start();
}
}
}
<resources>
<style name="MyTheme" parent="Theme.AppCompat.Light">
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
<?xml version="1.0" encoding="UTF-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@color/splash_background"/>
</item>
<item>
<ImageView android:id="@+id/animated_android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@anim/animate_android"
/>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/logo2"
android:duration="100" />
<item android:drawable="@drawable/Move"
android:duration="100" />
<item android:drawable="@drawable/logo"
android:duration="100" />
<item android:drawable="@drawable/icon"
android:duration="100" />
<item android:drawable="@drawable/About"
android:duration="100" />
</animation-list>
答案 0 :(得分:1)
你做错了一些事。
您需要使用布局而不是可绘制的基础。在布局中,您需要找到图像并为其设置适当的动画。
本教程最后有一个示例 - Xamarin.Forms (Android): Workaround For Splash Screen With Logo, Custom Background and Animation
基本步骤是: