ez4nick ez4nick - 3 months ago 22
Android Question

ImageView bounds extend beyond image

I have an

ImageView
defined as:

<ImageView
android:id="@+id/imageView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|top"
android:layout_marginBottom="50dp"
android:layout_marginTop="-80dp"
android:layout_toRightOf="@+id/prem_BACK"
android:layout_weight="0"
android:clickable="true"
android:paddingBottom="0dp"
android:src="@drawable/tester"
android:adjustViewBounds="false" />


and I see this in Android Studio in the layout preview:

enter image description here

And notice the bounds of the
ImageView
. Is it possible to have the bounds be along the actual edges of the image I am displaying?

Answer
<ImageView
android:id="@+id/imageView"
android:src="@drawable/tester"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"/>

Adding the scaleType to centerCrop should fix it for you. You can change the centerCrop to any other suggestions according to your need.