2012-08-07 200 views
8

我看了很多关于Stackoverflow的问题,并尝试了很多解决方法,但仍然无法使用。调整图像大小以适合Imageview

我想实现什么:

enter image description here enter image description here

但我实现这一目标:

enter image description here

这是我目前的XML代码:

<ImageView 
    android:id="@+id/image" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/text" 
    android:layout_gravity="center" 
    android:adjustViewBounds="true" 
    android:scaleType="centerInside" 
    android:src="@drawable/ic_action_search" /> 

回答

1

CenterInside,根据视图尺寸及其分辨率调整图像大小。因此,如果图像的大小为300 * 450,并且我们将此图像设置为缩放类型centerinside的图像视图,并且尺寸为200 * 400,那么它将使图像尺寸为200 * 300。根据目标尺寸,它下来使200是最小的宽度和高度。我希望我很清楚。如果您需要设置精确尺寸的尺寸,请按照Adeel的建议使用FItXY。

3

实现此目的的最佳方法是使用矩阵缩放图像(位图)。

另一种方法是使用之前创建它为您完成此库:

https://github.com/laurencedawson/ZoomableImageView

这将自动缩放图片以适应屏幕并添加捏缩放。

+0

如何去使用它吗?是否有任何教程或示例代码?因为我正在使用它在lazyload类的listview中加载图像。谢谢! – MrYanDao 2012-08-07 11:55:00

+0

对不起没有意识到你使用的是一个listview,可能不是最好的选择(由于垂直滚动)。 如果您看一下绘图和缩放代码,它应该可以帮助您。 – Ljdawson 2012-08-07 12:09:38

+0

好吧,会好的!非常感谢^^ – MrYanDao 2012-08-07 12:11:34

2

添加

<ImageView 
android:id="@+id/image" 
android:layout_width="fill_parent" 
android:layout_height="match_parent" 
android:layout_below="@+id/text" 
android:layout_gravity="center" 
android:adjustViewBounds="true" 
android:scaleType="fitXY" 
android:src="@drawable/ic_action_search" /> 
0

你想这样做的XML文件里面的权利?

<ImageView 
android:layout_width="size of image (in density pixels)" 
android:layout_height="size of image (in density pixels)" /> 

因此,例如:

<ImageView 
android:layout_width="60dp" 
android:layout_height="60dp" /> 
相关问题