我需要一些帮助,使背景图像在线性布局中垂直和水平拉伸(stretch)或缩放。但是,每次我尝试设置背景时,它都不会拉伸(stretch)图像以适合屏幕。我也不关心保持纵横比。
这是我目前在测试 xml 中得到的内容:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/title"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/background">
</LinearLayout>
在预览(和游戏)中看起来像这样:
如果我将 layout_height 更改为 fill_parent,我会得到一个重复的背景:
我确定该解决方案非常基本,但出于某种原因我错过了它。任何帮助将不胜感激
谢谢
最佳答案
不确定布局的背景属性有哪些可用的背景布局选项,但您始终可以将 ImageView 作为具有最大宽度和高度的外部 FrameLayout 中的第一个元素。然后,您放入布局中的任何其他内容都将绘制在此图像之上。当然,您可以只加载您想要的比例类型;例如 fitXY 也许是为了你想要达到的目标。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/backgroundDescription"
android:scaleType="centerCrop">
</ImageView>
...
关于android - 如何在 Android 线性布局中拉伸(stretch)/缩放背景图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19363083/