0

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.

iuni
  • 23
  • 9
  • Your image has outside padding. Please check the image instead of the image view. Use This Tool to check image padding - https://romannurik.github.io/AndroidAssetStudio/ – Sachin Oct 15 '20 at 06:21
  • Try using scale type in image view - android:scaleType="fitXY" – Shamir Kp Oct 15 '20 at 06:23
  • You will have to adjust the image size when generating it in Adobe. The `ImageView`is correct. As other comment say the image has outside padding. – Bogdan Android Oct 15 '20 at 06:25

1 Answers1

0

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" />
Shamir Kp
  • 488
  • 5
  • 9
  • Thank you for your response Shamir. It seems that `android:scaleType="fitXY"` has no effect on the ImageView. – iuni Oct 15 '20 at 06:31
  • Then check if the original image contain padding. Trim the image in photoshop then use. – Shamir Kp Oct 15 '20 at 06:47
  • It has no effect cause is the image the problem, not your imageView, your only solution is to trim manually your image in any image editor. – Bogdan Android Oct 15 '20 at 06:47
  • Bogdan, you were right. I trimmed the images, and they rendered better on the LinearLayout. Since I'm working with Soft UI elements, they have shadows that extend beyond the square, and those gave a lot of outside padding. Thank you for your help. – iuni Oct 15 '20 at 10:07