启动画面尺寸调整不正确。

12

我正在使用以下样式在我的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));
    }
  }
4个回答

9

对于背景可绘制对象,您应该使用layer-list。例如,创建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>
...

1
我想要提供位图的宽度,但在API 23以下不支持。有没有办法使标志在所有设备上变大?谢谢。 - Hilal

4

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


-3

当我在我的应用程序中遇到正确显示图像的问题时,我发现了这个有用的网站:Android比例类型

它展示了不同比例类型的结果。希望这能帮到你!


3
ScaleType 仅适用于 ImageView,但问题是关于 windowBackground - Miha_x64

-3
看一下:

Android:如何缩放Drawable或背景图像?

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接