简体   繁体   English

启动画面在切换到主屏幕之前表现出突然的运动

[英]Splash screen exhibiting abrupt motion before switching to the main screen

A splash screen implemented to be displayed while the Xamarin app loads in the background exhibits an unanticipated "upwards movement" while being displayed before switching to the main screen in Android devices (as seen in the following GIF of the loading screen).在 Xamarin 应用程序在后台加载时实现的启动画面在切换到 Android 设备的主屏幕之前显示时显示出意外的“向上移动”(如以下加载屏幕的 GIF 所示)。

带有不必要移动的启动画面

My first assumption regarding the solution of this issue was to use the same style settings for both the splash screen activity and the main activity but it is to no avail as the unwanted motion is still exhibited, which, as of this moment, is completely baffling as the cause just cannot be segregated.关于此问题的解决方案,我的第一个假设是对初始屏幕活动和主要活动使用相同的样式设置,但由于仍然显示不需要的动作,这无济于事,截至目前,这完全令人困惑因为根本无法分离原因。

The splash screen is implemented as per the logic corresponding to the following code and style sheets in the Android Project:启动画面是按照Android项目中以下代码和样式表对应的逻辑实现的:

Resources/drawable/splash_screen.xml资源/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_screen_background"/>
  </item>
  <!-- For bitmap images -->
  <!--<item>
    <bitmap
        android:src="@drawable/app_icon"
        android:tileMode="disabled"
        android:gravity="center"/>
  </item>-->
  <!-- For Android's drawable vector images -->
  <item 
    android:drawable="@drawable/android_v_drawable_application_icon"
    android:gravity ="center"
    android:width="150dp"
    android:height="214.010dp" />
</layer-list>

values/colors.xml值/颜色.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="launcher_background">#FFFFFF</color>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>

    <color name="splash_screen_background">#FFFFFF</color>
</resources>

value/styles.xml值/styles.xml

<?xml version="1.0" encoding="utf-8" ?>
<resources>

  <style name="MainTheme" parent="MainTheme.Base">
  </style>
  <!-- Base theme applied no matter what API -->
  <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
    <item name="windowNoTitle">true</item>
    <!--We will be using the toolbar so no need to show ActionBar-->
    <item name="windowActionBar">false</item>
    <!-- Set theme colors from https://aka.ms/material-colors -->
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">#2196F3</item>
    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">#1976D2</item>
    <!-- colorAccent is used as the default value for colorControlActivated
         which is used to tint widgets -->
    <item name="colorAccent">#FF4081</item>
    <!-- You can also set colorControlNormal, colorControlActivated
         colorControlHighlight and colorSwitchThumbNormal. -->
    <item name="windowActionModeOverlay">true</item>

    <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
  </style>

  <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">#FF4081</item>
  </style>

  <style name="SplashScreenTheme" parent ="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/splash_screen</item>
    <item name="android:windowNoTitle">true</item>  
    <item name="android:windowFullscreen">true</item>  
    <item name="android:windowContentOverlay">@null</item>  
    <item name="android:windowActionBar">false</item>
    <item name="windowActionModeOverlay">true</item>
  </style>
</resources>

Attributes to the Android Activity class pertaining to the splash screen:与初始屏幕相关的 Android Activity类的属性:

[Activity(Label = "App_App1", 
        Theme = "@style/SplashScreenTheme",
        Icon = "@mipmap/icon",
        ConfigurationChanges = ConfigChanges.ScreenSize 
                                | ConfigChanges.Orientation,
        MainLauncher = true, 
        NoHistory = true,
        ScreenOrientation = ScreenOrientation.Portrait
        )]

Thanks in advance.提前致谢。

I make the code sample to reproduce the "upwards movement".我制作了代码示例来重现“向上运动”。

In your description, you said "switching to the main screen in Android devices".在您的描述中,您说“切换到 Android 设备的主屏幕”。 I guess you have a special activity to do the splash screen.我猜你有一个特殊的活动来制作启动画面。 And have the main activity to LoadApplication .并拥有LoadApplication的主要活动。

When i set the same splash screen theme for the Splash_Activity and MainActivity , it would occure the "upwards movement".当我为Splash_ActivityMainActivity设置相同的初始屏幕主题时,它会发生“向上运动”。

在此处输入图片说明

So set the Theme to null or the default, it would be okay.所以把 Theme 设置为 null 或者默认,就可以了。

在此处输入图片说明

Splash_Activity:飞溅_活动:

 [Activity(Label = "App_App1",
    Theme = "@style/SplashScreenTheme",
    Icon = "@mipmap/icon",
    ConfigurationChanges = ConfigChanges.ScreenSize
                            | ConfigChanges.Orientation,
    MainLauncher = true,
    NoHistory = true,
    ScreenOrientation = ScreenOrientation.Portrait
    )]

MainActivity:主要活动:

 [Activity(Label = "SplashScreen", Icon = "@mipmap/icon", Theme = "@style/MainTheme", NoHistory = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]

You could download the source file from the GitHub for reference.您可以从 GitHub 下载源文件以供参考。 https://github.com/WendyZang/Test/tree/master/SplashScreen2/SplashScreen https://github.com/WendyZang/Test/tree/master/SplashScreen2/SplashScreen

删除附着在启动画面上的<style>标记的parent属性(即,在本例中为属性name="SplashScreenTheme"<style>标记)将删除不需要的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM