2013-01-07 103 views
0

我在我的android應用上有一個背景是一個PNG圖像。它的尺寸是800 x 480像素。 它被拉伸寬度明智,因此看起來不像我想要的那樣。由於圖像實際上是應用程序的背景,而不僅僅是一個imageView,我無法使用android:scaleType =「centerCrop」來使圖像平等地縮放。模擬器被拉伸的背景

我需要圖像來平等地填充背景。

我也嘗試過使用NinePatch drawable,但結果並不是很好 - 這個圖像變得模糊不清,或者當被垂直拉伸但不是寬度明智時確定。

before image after image as seen on emulator

這裏是我的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" 

是否有任何其他命令,我可以用它來得到正確顯示的背景?

+0

用黑色填充您的背景,並將您的標誌放在中心作爲圖像。 –

回答

1

解決這個使用draw9patch

Android的SDK /工具/ draw9patch

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

+0

我用過這個,但沒有得到正確的結果。我嘗試了下面這個工具: 1.在圖像周圍繪製一條線 - 這完全沒有區別 2.在圖像的頂部和左側畫一條線 - 這固定了拉伸的時候它是垂直延伸而不是水平延伸。 – Mustafa

+0

我在繪製9補丁工具上工作了一段時間,並使其工作! – Mustafa

0

使用imageview的

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

檢查,這也Link

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). 
+0

嗨,我使用了上面的代碼,但圖像仍在拉伸,我也試過了你提供的鏈接中的不同縮放類型(謝謝你的提問)。我注意到,如果圖像視圖是android:src,而不是android:background,那麼圖像不會被拉伸,但對於屏幕來說太大了。 – Mustafa