调整图像大小以适合Imageview

时间:2012-08-07 11:19:24

标签: android android-imageview

我在Stackoverflow上看了很多问题并尝试了很多解决方法,但它仍然没有用。

我想要实现的目标:

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" />

4 个答案:

答案 0 :(得分:3)

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

另一种方法是使用我之前创建的库,为您执行此操作:

https://github.com/laurencedawson/ZoomableImageView

这将自动缩放图像以适合屏幕,并添加缩放以进行缩放。

答案 1 :(得分:3)

添加

<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" />

答案 2 :(得分:1)

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

答案 3 :(得分: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" />
相关问题