【问题标题】:Xamarin splash screen image getting stretchedXamarin 初始屏幕图像被拉伸
【发布时间】:2022-01-07 12:59:14
【问题描述】:

首先,这是我的 style.xml 代码:


  <style name="MainTheme" parent="MainTheme.Base">
      <item name="colorAccent">#FF4627</item>
  </style>
    <style name="MyTheme" parent="android:style/Theme.Material.Light.DarkActionBar">
        <item name="android:colorPressedHighlight">@color/ListViewSelected</item>
        <item name="android:colorLongPressedHighlight">@color/ListViewHighlighted</item>
        <item name="android:colorFocusedHighlight">@color/ListViewSelected</item>
        <item name="android:colorActivatedHighlight">@color/ListViewSelected</item>
        <item name="android:activatedBackgroundIndicator">@color/ListViewSelected</item>
        <item name="android:colorEdgeEffect">#FF4627</item>
    </style>
    <style name="splashscreen" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/MDPI</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsTranslucent">false</item>
        <item name="android:windowIsFloating">false</item>
        <item name="android:backgroundDimEnabled">true</item>
    </style>
    <color name="ListViewSelected">#E39696</color>
    <color name="ListViewHighlighted">#E39696</color>
</resources>

这是我在 MainActivity.cs 中更改的内容:

    [Activity(Label = "Arboapp", Icon = "@drawable/ic_launcher", Theme = "@style/MainTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )]

这是我的 SplashActivity.cs:

[Activity(Label = "Arboapp", MainLauncher =true, Theme ="@style/splashscreen", NoHistory =true, Icon = "@drawable/icon")]
    public class SplashActivity : AppCompatActivity
    {
        

        protected override async void OnResume()
        {
            base.OnResume();
            StartActivity(typeof(MainActivity));

        }
        
    }

然后我用正确分辨率的文件填充每个 mipmap 文件夹(包括可绘制对象)。

即使这样,我得到的 spla 屏幕图像也是失真的。

应该是这样的:

【问题讨论】:

  • 这个问题多年来被问过很多次。在发布问题之前,请进行彻底的谷歌搜索。 (我已将标题编辑为技术上正确的术语,以说明正在发生的事情。)谷歌xamarin android splash screen image stretched。众多问答之一:Show splash screen image with auto fit - 我选择了那个,因为“自动适应”是您想要发生的事情的术语。 (填充而不拉伸)。

标签: xamarin xamarin.forms xamarin.android splash-screen android-drawable


【解决方案1】:

图像只需要从drawable文件夹中引用,其他文件夹应该具有完全相同名称的图像。

设备将根据分辨率选择正确的文件夹和图像 您可以查看谷歌文档以获取更多详细信息:https://developer.android.com/training/multiscreen/screendensities#TaskProvideAltBmp

这里是关于 android 闪屏的微软文档: https://docs.microsoft.com/en-us/xamarin/android/user-interface/splash-screen

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-23
    • 1970-01-01
    • 1970-01-01
    • 2011-06-07
    • 1970-01-01
    • 2020-07-05
    • 2017-10-07
    • 1970-01-01
    相关资源
    最近更新 更多