我如何删除额外的空间上面和下面的图像查看?

我有一个非常简单的图像内的 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>
47717 次浏览

您的问题可能是您没有设置缩放类型... ... 将它添加到 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" />

在你以上的 imageView只需添加 android:scaleType="fitXY"

试试这个

android:adjustViewBounds="true"

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

添加属性必须足够:

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" />

如果您的图像视图高度是 match _ father,即使您设置了 android,调整 ViewBounds = “ true”ImageView 也会在顶部和底部添加一些额外的空白。因此,将 ImageView 高度更改为 wrash _ content 并设置 android: adjViewBounds = “ true”

比如说

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

试试这个

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

这是完美的解决方案

 <ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitXY"
/>

它不会在任何一边留下任何额外的 dp。但是,如果图像不是肖像图像,则图像会失真。

通过添加以下代码,可以将 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

如果没有对图像的特殊要求,使用 可绘制的节点文件夹。然后使用 android: adjustViewBounds = "true"作为默认文件夹。

如果使用 可绘制的节点,则不需要设置 android:adjustViewBounds = "true"

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

这行代码将解决这个问题

android:adjustViewBounds="true"

别忘了旋转图像