android-位图可绘制为背景图像以填充屏幕但保持纵横比

dor*_*uck 5 scaling android background drawable

我不知道如何使用位图作为背景图像,使其缩放以填充屏幕但保持纵横比。到目前为止,我只找到了使用额外的 ImageView 而不是背景图像并使用 android:scaleType="centerCrop" 的解决方案

...
<ImageView 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:contentDescription="@string/desc_background"
    android:scaleType="centerCrop"
    android:src="@drawable/background"
/>
...
Run Code Online (Sandbox Code Playgroud)

不过,我更愿意通过在窗口上设置活动背景来解决这个问题

 <style ...>
 <item name="android:windowBackground">@drawable/background</item>
Run Code Online (Sandbox Code Playgroud)

正如我被告知(并看到)这要快得多。(@drawable/background 是一个 XML 可绘制对象)

似乎是一个常见的任务,但到目前为止我找不到解决方案。任何建议将不胜感激。

谢谢

马丁