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

Splash screen exhibiting abrupt motion before switching to the main screen

在 Android 设备中切换到主屏幕之前显示 Xamarin 应用程序在后台加载时显示的初始屏幕显示出意外的“向上移动”(如下面的 GIF 所示)加载屏幕)。

关于这个问题的解决方案,我的第一个假设是对初始屏幕 activity 和主屏幕 activity 使用相同的样式设置,但它无济于事,因为不需要的动作是仍然展出,截至目前,这完全令人困惑,因为原因无法隔离。

闪屏按照Android项目中如下代码和样式表对应的逻辑实现:

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_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 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

<?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>

Android Activity class 与初始屏幕相关的属性:

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

提前致谢。

我制作代码示例来重现“向上运动”。

在您的描述中,您说“切换到 Android 设备中的主屏幕”。我猜你有一个特殊的 activity 来做闪屏。并有主要 activity 到 LoadApplication.

当我为 Splash_ActivityMainActivity 设置相同的闪屏主题时,会出现“向上运动”。

所以把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
    )]

主要活动:

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

您可以从GitHub下载源文件以供参考。 https://github.com/WendyZang/Test/tree/master/SplashScreen2/SplashScreen

删除粘附在初始屏幕上的 <style> 标签的 parent 属性(即在本例中具有 name="SplashScreenTheme" 属性的 <style> 标签)会删除不需要的行为。