编辑:部分答案
如果两个维度在XML设置,其行为与预期相同,例如错误ImageView的尺寸
android:layout_width="250dp"
android:layout_height="250dp"
如果一个人留下来WRAP_CONTENT,事实并非如此。
原贴
这里是我的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/board"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/board" />
</LinearLayout>
为什么我在屏幕上看到的图像有正确的尺寸(屏幕高度×屏幕高度,因为它是一个正方形的位图,我设置match_parent为高度),但如果我调用ImageView.getWidth()和ImageView.getHeight()它给我的屏幕尺寸?
问候
为什么由于wrap_content被设置,所以视图比图像大?你能解释一下吗?非常感谢。 – pouzzler 2012-04-16 19:35:24
这是'ImageView'缩放的方式,以便用'match_parent'来适应高度。您使用的图片比您要填充的尺寸要大。默认情况下,它设置为居中图像并适合它,以便显示所有内容。它会缩小你的图像。这就是为什么我说整个View的像素尺寸与显示图像的像素尺寸不同。 – DeeV 2012-04-16 19:48:34