Android Imageview Maintain Aspect Ratio

Oct 28, 2018

The following will match parent's width and adjust height to maintain aspect ratio.

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/placeholder_150"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop"
    />

NOTE: @drawable/placeholder_150 is a square image.

NOTE: You might want to experiment with scaleType fitCenter or fitXY as well.

References:

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.