我无法弄清楚如何使用位图作为背景图像,使其缩放以填满屏幕但保持纵横比。到目前为止,我只找到了使用附加 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"
/>
...
尽管如此,我更愿意通过在窗口上设置 Activity 背景来解决这个问题
<style ...>
<item name="android:windowBackground">@drawable/background</item>
我被告知(并且看到)这要快得多。 (@drawable/background 是一个 XML 可绘制对象)
似乎是一项常见的任务,但到目前为止我找不到解决方案。任何建议将不胜感激。
谢谢
马丁
最佳答案
您是否尝试将 adjustViewBounds 属性设置为 true ?
http://developer.android.com/reference/android/widget/ImageView.html#attr_android:adjustViewBounds
关于android-位图可绘制为背景图像以填充屏幕但保持纵横比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12208341/