【问题标题】:How do I remove extra space above and below imageView?如何删除 imageView 上方和下方的额外空间?
【发布时间】:2013-02-15 01:43:06
【问题描述】:

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

这是它的样子:

代码如下:

<?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>

【问题讨论】:

    标签: android imageview


    【解决方案1】:

    这行代码就能解决问题

    android:adjustViewBounds="true"
    

    别忘了旋转图片

    【讨论】:

    • 这个问题早在几年前就有答案了!
    【解决方案2】:

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

    如果你使用drawable-nodpi,你不需要设置android:adjustViewBounds = "true"

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

      • 把它改成 ´android:scaleType="fitXY"´
      • 这将改变纵横比,使事物看起来被拉伸或挤压。
      【解决方案4】:

      试试这个

      android:adjustViewBounds="true"

      【讨论】:

      • 在我的代码中,这仅适用于 'android:layout_width="match_parent" android:layout_height="match_parent"'
      • 谢谢。太棒了,超级有用。
      【解决方案5】:

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

      适用于我之前和之后的图片

      【讨论】:

        【解决方案6】:

        这是完美的解决方案

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

        它不会在任何一侧留下任何额外的单个 dp。但是如果不是纵向图像,图像会失真。

        【讨论】:

          【解决方案7】:

          试试这个

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

          【讨论】:

            【解决方案8】:

            如果您的图像视图高度为 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"/>
            

            【讨论】:

              【解决方案9】:

              添加属性就足够了:

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

              【讨论】:

                【解决方案10】:

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

                【讨论】:

                  【解决方案11】:

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

                  【讨论】:

                  猜你喜欢
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 2016-11-23
                  • 1970-01-01
                  • 2020-09-01
                  • 1970-01-01
                  相关资源
                  最近更新 更多