0

我的 android 应用程序有一个背景,是一个 png 图像。它的大小为 800 x 480 像素。它在宽度上被拉伸,因此看起来不像我想要的那样。由于图像实际上是应用程序的背景,而不仅仅是一个 imageView,我无法使用 android:scaleType="centerCrop" 来使图像均匀缩放。

我需要图像来均匀地填充背景。

我也尝试过使用 NinePatch drawable,但结果并不好 - 图像变得模糊或在垂直拉伸时还可以,但不是宽度方向。

图像前 在模拟器上看到的图像后

这是我的 XML 代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/menu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" 

有没有其他命令可以让背景正确显示?

4

2 回答 2

1

解决这个使用 draw9patch

android-sdk/工具/draw9patch

https://developer.android.com/tools/help/draw9patch.html

于 2013-01-07T20:53:28.927 回答
0

使用图像视图

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/your_image"
android:scaleType="fitCenter"
/>

检查这个也链接

ImageView.ScaleType     CENTER_CROP

Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding). 
于 2013-01-07T20:54:28.027 回答