0

I have images that could be either 300x600px or 600x300px. I want them to be displayed in a box of 50dp. So the image would be 25dp x 50dp or 50x25dp depending on its ratio

I have tried various things and I am going crazy

<RelativeLayout
    android:layout_width="50dp"
    android:layout_height="50dp">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/image"/>
</RelativeLayout>

or

(this doesn't crop anything...)

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:scaleType="centerCrop"
        android:adjustViewBounds="true"
        android:background="@drawable/image"/>

But none work and it seems that whatever value I put in scaleType is ignored

Thomas
  • 8,306
  • 8
  • 53
  • 92

1 Answers1

0

Use scaleType="fitCenter" (if you want to upscale small images) or scaleType="centerInside" (otherwise).

Disable adjustViewBounds.

rom1v
  • 2,752
  • 3
  • 21
  • 47