如何删除imageView上方和下方的额外空间?

时间:2013-02-28 18:21:09

标签: android imageview

我在RelativeLayout内有一个非常简单的图像,由于某种原因,我在顶部和底部有额外的间距,我无法删除。我该如何清除它?

这是它的样子:

Image from Eclipse preview

以下是代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:src="@drawable/slice11pp" />
</RelativeLayout>

10 个答案:

答案 0 :(得分:217)

试试这个

android:adjustViewBounds="true"

答案 1 :(得分:7)

在上面的imageView中添加android:scaleType="fitXY"

答案 2 :(得分:5)

您的问题可能是您没有设置比例类型...将其添加到ImageView的XML中,“fitCenter”应该是正确的,但还有其他,请检查:ScaleType

<ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:src="@drawable/slice11pp"
            android:scaleType="fitCenter" />

答案 3 :(得分:4)

添加属性必须足够:

android:adjustViewBounds="true"

例如:

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/slice11pp"
        android:adjustViewBounds="true" />

答案 4 :(得分:2)

如果你的图片视图高度是match_parent,即使你设置了android:adjustViewBounds =“true”,ImageView会在顶部和底部添加一些额外的空白区域。所以,将ImageView高度更改为wrap_content并设置android:adjustViewBounds =“true”

例如

<ImageView
  android:id="@+id/img_view"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:adjustViewBounds="true"/>

答案 5 :(得分:1)

通过添加

android:scaleType =“ centerCrop”

<ImageView
    android:id="@+id/image"
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:src="@drawable/temp_image"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop"/>

在图像前后为我工作 Before and After Image

答案 6 :(得分:1)

这行代码将解决问题

android:adjustViewBounds="true"

不要忘记旋转图像

答案 7 :(得分:0)

只需在Image视图中添加ScaleType =“fitxy”

答案 8 :(得分:0)

试试这个

<ImageView
     (...)
     android:adjustViewBounds="true" />

答案 9 :(得分:0)

如果对图像没有特殊要求,请使用 drawable-nodpi 文件夹。然后android: adjustViewBounds = "true"成为默认值。

如果使用 drawable-nodpi ,则无需设置android:adjustViewBounds = "true"

我认为这是最轻松的方法。

相关问题