Without using any custom classes or libraries:
<ImageView
android:id="@id/img"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter" />
scaleType="fitCenter"
(default when omitted)
scaleType="centerInside"
src
is smaller than parent widthsrc
is larger than parent widthIt doesn't matter if you use android:src
or ImageView.setImage*
methods and the key is probably the adjustViewBounds
.