How do I remove extra space above and below imageView?

萝らか妹 提交于 2019-11-28 06:08:30
Sagar V.

Try this

android:adjustViewBounds="true"

k0sh

In your above imageView just add android:scaleType="fitXY"

Your problem is probably that you have no scale type set... Add it to the XML for the ImageView, "fitCenter" should be correct, but there are others, check: 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" />

Must be enough adding the property:

android:adjustViewBounds="true"

for example:

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

If your image view height is match_parent, even if you set android:adjustViewBounds="true" ImageView will add some extra blank space at top and bottom side. so, change ImageView height to wrap_content and set android:adjustViewBounds="true"

for example

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

android:scaleType="centerCrop" by adding this

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

works for me Before and After Image

Use drawable-nodpi folder if there is no specific requirement for images. Then android: adjustViewBounds = "true" acts as the default.

If you use drawable-nodpi you don't need to set android:adjustViewBounds = "true".

I think this is the most effortless method.

just add ScaleType="fitxy" inside the Image view

Try this

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

this is the perfect solution

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

it will not leave any extra single dp in any side. however the image will be distorted if it is not portrait image.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!