【发布时间】:2011-09-29 18:19:43
【问题描述】:
我有一个 640 像素宽、208 像素高的 PNG,我已将其放置在我的 /drawable 文件夹中,但我很难将其正确放置在 ImageView 中。我想缩放图像以使其水平分辨率最大化,并且我希望它在垂直方向上仅缩放以保持成比例。
我遇到的问题是我的 ImageView 最终比适合图像所需的高。图像本身看起来很完美;与屏幕一样宽且成比例。但是 ImageView 似乎在顶部和底部都有填充。据我所知,ImageView 包含的可绘制对象实际上太高了。
我无法发布图片,因为我是 SO 新手,但如果我这样做了,那将是图形布局视图。当我单击 ImageView 时,它周围会出现常规的蓝色框,但顶部和底部都有填充,与我在设备上看到的填充相同。即使我拖动蓝色框以尝试调整 ImageView 的大小,我也不允许将其设置为比现在更小(可能是因为 ImageView 认为 drawable 有那么高,或者其他什么)。据我所知,这可能与图像的密度有关...ImageView 在 hdpi 设备上最终为 312 像素高 (208*1.5)。
这是我的 XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:id="@+id/back" android:src="@drawable/categoryheader2"
android:layout_width="wrap_content" android:layout_height="wrap_content">
</ImageView>
</RelativeLayout>
提前感谢您的帮助!
【问题讨论】:
标签: android android-layout android-widget android-imageview