【问题标题】:Splash Screen Image is too Stretched启动画面图像过度拉伸
【发布时间】:2019-04-30 14:25:01
【问题描述】:

我的可绘制文件夹中有图像,我将它们调整为标准尺寸并将它们放在每个文件夹中。但是当我启动我的应用程序并且 MainActivity 运行时,我的 SplashScreen 图像出现拉伸并且在屏幕上看起来很糟糕。我在网上看了答案,没有任何效果。

如何使图像在启动画面上看起来正常。

这是我的 MainActivity.cs

        [Activity(Label = "Peppy", Icon = "@mipmap/bicon", Theme = "@style/peppy", MainLauncher = true, NoHistory = true)]
        public class SplashActivity : Activity
    {
           protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            StartActivity(typeof(MainActivity));            
        }
    }

这就是我在 style.xml 中定义我的风格的方式

 <style name="peppy" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/bluesplash</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:colorPrimaryDark">#1976D2</item>
  </style>

  <style name="Main Theme" parent="MainTheme.Base"></style>

我希望 SplashScreen 图像完全适合我想要的屏幕。谢谢

【问题讨论】:

    标签: xml xamarin.forms splash-screen


    【解决方案1】:

    我的 drawables 文件夹中有一个 splashScreen.xml

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

    使图像居中而不扭曲。

    活动是这样的

    using System.Threading.Tasks;
    using Android.App;
    using Android.Content;
    using Android.OS;
    using Android.Support.V7.App;
    using Android.Util;
    using App1.Droid;
    
    namespace com.xamarin.sample.splashscreen
    {
        [Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true)]
        public class SplashActivity : AppCompatActivity
        {
            static readonly string TAG = "X:" + typeof(SplashActivity).Name;
    
            public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
            {
                base.OnCreate(savedInstanceState, persistentState);
                Log.Debug(TAG, "SplashActivity.OnCreate");
            }
    
            // Launches the startup task
            protected override void OnResume()
            {
                base.OnResume();
                StartActivity(new Intent(Application.Context, typeof(MainActivity)));
            }
    
            // Prevent the back button from canceling the startup process
            public override void OnBackPressed() { }
        }
    }
    

    【讨论】:

    • 您是否也有引用 splashScreen.xml 中可绘制的样式?
    • 在文档中可以找到更完整的示例(类似于此答案):Creating a Drawable for the Splash Screen。紧随其后的部分“实现主题”展示了启动屏幕 xml 的使用方式。
    猜你喜欢
    • 2021-12-22
    • 1970-01-01
    • 2021-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-05
    • 1970-01-01
    相关资源
    最近更新 更多