2013-09-28 36 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