如何在Xamarin中创建初始屏幕以适合所有屏幕尺寸

问题描述

我能够正常显示初始屏幕,但是我需要根据屏幕分辨率提供正确大小的初始图像。在我检查过的所有示例中,他们都说将splashscreen.png放入可绘制的文件夹中,并在splash.xml中引用它,该文件随后在style.xml中引用,该style.xml用作启动活动主题

在Resources> drawable内部的splash.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <color android:color="@color/launcher_background"/>
  </item>
  <item>
    <bitmap
        android:src="@drawable/splashscreen"
        android:tileMode="disabled"
        android:gravity="center"
        />
  </item>
</layer-list> 

内部资源>值> styles.xml:

<style name="splashscreen" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/splash</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>

这是我的问题:

Resources中有一个drawable文件夹,Resources中有单独的mipmap文件夹,这些文件夹应该存放不同大小的启动屏幕。我看到的示例仅引用可绘制的单个图像。所以问题是,如何根据设备分辨率适当地引用正确的splashscreen.png?

来源:

https://docs.microsoft.com/en-us/xamarin/android/user-interface/splash-screen

https://www.xamarinhelp.com/creating-splash-screen-xamarin-forms/

解决方法

仅需要从可绘制文件夹中引用图像,其他文件夹中的图像应具有完全相同的名称。基于分辨率的设备会自动选择正确的可绘制文件夹和其中的图像。 有关更多详细信息,Click here