删除 Android 中 ImageView 上方和下方的 space

Removing space above and below ImageView in Android

你好,我需要帮助,因为我 在我的 android xml 文件中添加一个 ImageView,我得到一个 额外的 space 在它上面和下面 我试图查看我可以用来删除它的选项,其中之一是添加 android:adjustViewBounds="true" 但是当我这样做时,它完全删除了我的操作栏下面是我的代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.fred.yebo.MainFragment">

  <ImageView
      android:id="@+id/yeboAdd"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:src="@drawable/dice"

      />

</RelativeLayout>

您可以尝试使用 imageView

的 scaleType 属性
android:scaleType="fitXY"

这条线根据你的尺寸缩放你的图像 container.There 是你可以尝试的 scaleType 的一些属性,这将更好地帮助你 case.Hope!

试试这个属性:

android:adjustViewBounds="true"

自动缩放视图的高度。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.fred.yebo.MainFragment">

    <ImageView
        android:id="@+id/yeboAdd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:src="@drawable/cal" />

</RelativeLayout>

check this answer.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.fred.piku.MainFragment">

    <ImageView
        android:id="@+id/pikuAdd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/dice" />

</RelativeLayout>