I’m trying to get an ImageView to have a specific width (let’s say 100dips) but to scale so that the height is whatever value that maintains ratio, so if 4:3 then 75 dips, if 4:5 then 120 dips, etc.
I’ve tried a few things, but nothing is working. This is my current attempt:
<ImageView
android:id="@+id/image"
android:layout_height="wrap_content"
android:layout_width="100dip"
android:adjustViewBounds="true"
android:src="@drawable/stub"
android:scaleType="fitCenter" />
The wrap_content for height didn’t improve things, it just made the entire image smaller (but did maintain aspect ratio). How can I Accomplish what I’m trying to do?
Add the follwing class to your project and change your layout like this
View
Class