Tuesday, September 3, 2013

Maximize an ImageView on Android

Problem
How to maximize an ImageView on Android while keeping the aspect ratio? There's a lot of combinations available on the Internet but the following code alone was able to solve my problem.

Solution
<ImageView android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="1" android:scaleType="fitCenter" />

Important Note
Make sure the ImageView is inside a LinearLayout for the android:layout_weight to work.

Source
Comment of Mohsen Afshin on stackoverflow.com