首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用SVG动画创建Android启动屏幕

使用SVG动画创建Android启动屏幕
EN

Stack Overflow用户
提问于 2022-03-25 18:20:44
回答 1查看 673关注 0票数 0

我正在用Xamarin.Forms开发一个应用程序,我正在尝试将启动屏幕插入到我的安卓项目中。

我找到了一些教程,用于创建带有背景颜色和静态png图像的splash屏幕,但我想使用我的svg动画作为启动屏幕。我想我可以遵循一个静态图像教程,只需用svg动画替换png图像,但它没有工作。到目前为止,我的情况如下:

SplashActivity.cs

代码语言:javascript
运行
复制
[Activity(Label = "SplashActivity", Theme = "@style/Theme.Splash", MainLauncher = true, NoHistory = true)]
    public class SplashActivity : Activity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
        }

        protected override void OnResume()
        {
            base.OnResume();
            Task startupWork = new Task(() => { SimulateStartup(); });
            startupWork.Start();
        }

        async void SimulateStartup()
        {
            await Task.Delay(5000);
            StartActivity(new Intent(Application.Context, typeof(MainActivity)));
        }
    }

MainActivity.cs

代码语言:javascript
运行
复制
// I only changed the MainLauncher property to false
[Activity(Label = "MyApp", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        ...
    }

关于styles.xml (在Xamarin.Android项目中):

代码语言:javascript
运行
复制
<style name="Theme.Splash" parent="android:Theme">
    <item name="android:windowBackground">@drawable/desenhando5s</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
    <item name="colorPrimaryDark">#004632</item>
  </style>

当我运行应用程序时,它只显示一个黑色屏幕作为启动屏幕,然后显示我的登录页面和往常一样。有人能告诉我怎样才能把我的动画设置成飞溅的屏幕吗?

(FYI:万一有人想知道,我用SVGator制作了动画)

EN

Stack Overflow用户

回答已采纳

发布于 2022-03-28 09:20:29

您可以使用FFImageLoadingSplashActivity中加载svg映像,而不是在styles.xml中设置它。

溅屏:

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FFImageLoading.Views.ImageViewAsync
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

代码:

代码语言:javascript
运行
复制
protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        // Create your application here

        SetContentView(Resource.Layout.layout5);

        var filePath = "check";
        var imageView = FindViewById<ImageView>(Resource.Id.imageView);
        ImageService.Instance.LoadCompiledResource(filePath).WithCustomDataResolver(new SvgDataResolver(64, 0, true)).Into(imageView);
    }
    protected override void OnResume()
    {
        base.OnResume();
        Task startupWork = new Task(() => { SimulateStartup(); });
        startupWork.Start();
    }
    async void SimulateStartup()
    {
        await Task.Delay(5000);
        StartActivity(new Intent(Application.Context, typeof(MainActivity)));
    }

更新:

请检查一下截图。.svg图像位于drawable文件夹中。layout5是布局文件夹中的启动屏幕。

票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71621508

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档