androidandroid-studioadobe-xd

ImageView Has Unwated Padding


I've imported some images from Adobe XD in PNG format to Android Studio. The images seem to come with extra padding. I'm attempting to fill the ImageView with just the size of the imported image (in this case messages).

This is my xml:

<ImageView
    android:src="@drawable/messages"
    android:id="@+id/imageView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    tools:layout_editor_absoluteX="79dp"
    tools:layout_editor_absoluteY="184dp" />

These images show what the padding looks like:

Example 1: image has padding

Example 2: ImageView is quite larger than the actual image.

Is there anyway to get the ImageView to wrap around the image exactly without the padding?

Thank you for your help.


Solution

  • Try using android:scaleType:

    <ImageView
        android:src="@drawable/messages"
        android:id="@+id/imageView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:scaleType="fitXY" 
        tools:layout_editor_absoluteX="79dp"
        tools:layout_editor_absoluteY="184dp" />