我想要理解一些东西。我看到一个奇怪的事情是,当我在宽度和高度中使用wrap_content
时,图像的尺寸比插入的真实像素大小要大。为什么会这样呢?
我的代码中使用了wrap_content
:
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:src="@drawable/header" />
这是我的代码,其中图片的像素大小精确指定:
<ImageView
android:id="@+id/imageView1"
android:layout_width="378px"
android:layout_height="155px"
android:adjustViewBounds="false"
android:src="@drawable/header" />
正如您所看到的,这是确切的像素大小:
为什么会这样呢?我以为wrap_content
应该根据内容大小包裹视图,那为什么在屏幕上它会更大呢?
header
文件夹在哪个目录中? - Mohsin Naeemwrap_content
只是简单地将内容包装起来 :) 但是,如果您的图像位于mdpi文件夹
中,而您的设备是hdpi
,那么您的图像看起来会很小,因为它在缩放后显示图像(378 x 155)/1.5
,但在mdpi设备
上,它会以(378 x 155)的形式显示。 - Mohsin Naeem