2013-09-28 39 views
1

我有這種情況。因此,圖像比容器在容器中居中放置一個圖像並裁剪剩餘的圖像

enter image description here

我希望它縮小或擴大取決於容器尺寸較大,但在同一時間把它的中心和裁剪其餘(水平)。

所以我做了這樣的事情。

<?xml version="1.0" encoding="utf-8"?> 
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
    android:src="@drawable/header_long" 
    android:gravity="center" 
    android:antialias="true" 
    android:dither="true"/> 

但現在看起來像這樣。頂部,底部,左側和右側被裁剪。

enter image description here

我希望它是這樣的。

enter image description here

回答

1

試試這個

android:scaleType="centerCrop" 
0

像ben75建議,你可以把你的位圖到上午的ImageView和使用

android:scaleType="centerCrop" 

如果你想用你的圖片作爲背景,考慮將它製作成9幅圖像。如果圖像太小,它們會定義可能拉伸的區域。他們還定義填充。請注意,9貼片圖像會根據需要增長,但它們永遠不會縮小,因此請將它們縮小至您喜歡的最小尺寸。

+0

我把上面可繪製的位圖放到一個ImageView中,做了'centerCrop',但是頂部和底部被裁剪,就好像它沒有縮放 – bman

+0

在應用'centerCrop'之前你先縮放了它嗎? – Zyoo