gpt4 book ai didi

animation - Xamarin 安卓 : Animated Splash Screen

转载 作者:行者123 更新时间:2023-12-04 12:46:25 26 4
gpt4 key购买 nike

我想创建一个动画闪屏,但出现此错误:

Android.Content.Res.Resources+NotFoundException: File res/drawable/splash_screen.xml from drawable resource ID #0x7f0200bc



当我将 Imageview 的 src 更改为 @drawable/logo2 时,我的代码有效,但随后我得到了一个静态 splas 屏幕。

SplashActivity.cs
[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();
}
}
}

资源/值/Style.xml
<resources>
<style name="MyTheme" parent="Theme.AppCompat.Light">
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>

资源/Drawable/splash_screen.xml
<?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>

资源/动画/animate_android.xml
<?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>

最佳答案

你做错了几件事。

您需要使用 Layout 而不是 drawable 作为基础。在布局中,您需要找到图像并为其设置适当的动画。

本教程最后有一个示例 - Xamarin.Forms (Android): Workaround For Splash Screen With Logo, Custom Background and Animation

基本步骤是:

  • 创建 Spalsh 布局
  • 创建一个drawabale
  • 创建动画
  • 在您的事件中将它们全部连接在一起(请注意,如果您将动画添加到“OnCreate”方法,动画将不会启动。)。
  • 关于animation - Xamarin 安卓 : Animated Splash Screen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38720655/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com