【问题标题】:ImageView within RelativeLayout has top and bottom paddingRelativeLayout 中的 ImageView 具有顶部和底部填充
【发布时间】: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


    【解决方案1】:

    我猜 ImageView 上的 android:adjustViewBounds="true" 应该可以解决问题。我最近在尝试scale an image to fit the whole width of the view without loosing its proportions时遇到了类似的问题。

    【讨论】:

    • 老问题,但仍然出现在我的应用程序中 - 感谢您的回复!如果可行,我会尝试并接受答案!
    • 真的很遗憾你没有得到答案。但是你为我节省了一些搜索,谢谢
    • 非常感谢,知道这个可能很标准,很少有人问它,对于我作为初学者来说它非常方便。
    【解决方案2】:

    您是否在ImageView 上尝试了标签:android:scaleType="fitXY"android:scaleType="centerCrop"

    【讨论】:

    • 感谢您的回复,但没有一个 scaletypes 工作。 fitXY 只是使图像更高以适应(删除“填充”但弄乱了图像的比例), centerCrop 也使图像更高,但也使其更宽以保持比例,但当然现在侧面被裁剪. :(
    猜你喜欢
    • 2012-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-02
    • 1970-01-01
    • 2014-08-28
    • 1970-01-01
    相关资源
    最近更新 更多