2

I would like to know how you adjust the "hitbox" of an ImageView to the Image inside, so that there are no empty spaces around the image. I want to make a game and so it feels odd when you click on an empty space next to the Image but it still counts as "a click on the image". I would really appreciate help. Thank you in advance.

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/soraka"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:src="@drawable/image"
    android:adjustViewBounds="true"
    android:maxWidth="300dp"
    android:maxHeight="300dp"
    android:scaleType="fitXY"
    android:layout_alignParentEnd="false"
    android:layout_alignParentStart="false"
    android:cropToPadding="false"
    android:padding="0dp" />
404response
  • 93
  • 1
  • 8

1 Answers1

1

First of all open your image in some image editor and check if it fills entire canvas. Second - use android:scaleType="fitXY". But be carefull with aspect ratio:

Scale in X and Y independently, so that src matches dst exactly. This may change the aspect ratio of the src.

Also remove all paddings, margins from ImageView.

j2ko
  • 2,479
  • 1
  • 16
  • 29