6

I have a layout like this:

<LinearLayout
    android:layout_width="32dp"
    android:layout_height="32dp"
    android:layout_marginEnd="8dp"
    android:gravity="start|center_vertical"
    android:orientation="horizontal"
    android:layout_weight="0.25">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="20dp"
        android:background="@drawable/reply_icon"
        android:scaleType="fitCenter"
        android:adjustViewBounds="true"
        />

</LinearLayout>

I'm trying to get the ImageView to fit its height (20dp) and auto-adjust the width (while keeping its aspect ratio), however, it comes out looking stretched like this:

screenshot

How can I fix this?

William Price
  • 4,033
  • 1
  • 35
  • 54
user5721807
  • 81
  • 1
  • 5

1 Answers1

0

Add two attributes: (android:adjustViewBounds and android:scaleType=) to your ImageView for keep aspect ratio

android:adjustViewBounds="true"
android:scaleType="centerCrop"

Hope this help

Linh
  • 57,942
  • 23
  • 262
  • 279