【问题标题】:Splash screen is resizing incorrectly启动画面的大小调整不正确
【发布时间】:2013-05-11 19:24:23
【问题描述】:

我正在使用下面的样式在我的 Xamarin Android 应用程序中显示初始屏幕,但是图像总是显示不正确的大小。我希望它以正确的尺寸调整大小,但它总是会扩展以适应屏幕。

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <style name="Theme.Splash" parent="android:Theme">
    <item name="android:windowBackground">@drawable/splashscreenimage</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:adjustViewBounds">true</item>
    <item name="android:scaleType">centerCrop</item>
  </style>
</resources>

闪屏活动

  [Activity(MainLauncher = true, Theme = "@style/Theme.Splash", NoHistory = true)]
  public class SplashScreenActivity : Activity
  {
    protected override void OnCreate(Bundle bundle)
    {
      base.OnCreate(bundle);

      // Start our real activity
      StartActivity(typeof(LoginActivity));
    }
  }

【问题讨论】:

    标签: android splash-screen xamarin


    【解决方案1】:

    对于背景可绘制,您应该使用图层列表。例如制作 bitmap_splash.xml:

    <item android:drawable="@color/background"/>
    
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/splashscreenimage" />
    </item>
    

    然后以你的风格使用它:

    ...
    <style name="Theme.Splash" parent="android:Theme">
        <item name="android:windowBackground">@drawable/bitmap_splash</item>
    ...
    

    【讨论】:

    • 我想给出位图宽度,但是在 api 23 下不支持它。有没有办法让所有设备的标志都变大?谢谢
    【解决方案2】:

    一个问题是 windowBackground 被调整为全屏大小,包括设备顶部或底部的状态栏。但是状态栏仍然显示。我对Android Activity Background Image 的回复使用了不包括状态栏的windowContentOverlay。

    【讨论】:

      【解决方案3】:

      当我无法在我的应用中正确显示图像时,我发现了这个有用的网站:Android scale types

      它显示了您可以使用的不同类型的量表的结果。希望这会有所帮助!

      【讨论】:

      • ScaleType 仅适用于ImageView,但问题是关于windowBackground
      【解决方案4】:

      看看:

      Android: Scale a Drawable or background image?

      基本上,这允许您指定当图像小于屏幕的视图边界时如何剪切或拉伸图像。我认为这个答案的作者给出了一个很好的解释,它可能就是你要找的。​​p>

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-09-27
        • 1970-01-01
        • 2021-10-28
        • 1970-01-01
        • 2011-01-11
        • 1970-01-01
        • 1970-01-01
        • 2014-03-09
        相关资源
        最近更新 更多