微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

闪屏在切换到主屏幕之前呈现突然运动

如何解决闪屏在切换到主屏幕之前呈现突然运动

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

Splash screen with unwanted movement

关于此问题的解决方案,我的第一个假设是对初始屏幕活动和主要活动都使用相同的样式设置,但由于仍然表现出不必要的动作而无济于事,到目前为止,完全令人困惑,因为原因无法隔离。

初始屏幕是根据与Android项目中以下代码和样式表相对应的逻辑实现的:

资源/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类的属性

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

谢谢。

解决方法

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

在您的描述中,您说的是“切换到Android设备的主屏幕”。我猜您有一个特殊的活动要做启动画面。并且具有LoadApplication的主要活动。

当我为Splash_ActivityMainActivity设置了相同的启动画面主题时,它将发生“向上运动”。

enter image description here

因此,将主题设置为null或默认值,就可以了。

enter image description here

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",Theme = "@style/MainTheme",ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]

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

,

删除附着在启动屏幕上的parent标签的<style>属性(即,在这种情况下,具有属性<style>的{​​{1}}标签)将删除不需要的行为

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。