Learning Android Development
Android ImageView AdjustViewBounds Demystified
Deduce the logic of ImageView with AdjustViewBounds
After understanding ScaleType fully, this is another little thing that worth master, AdjustViewBounds which is an attribute of ImageView that you set as true and false.
<androidx.appcompat.widget.AppCompatImageView
android:adjustViewBounds="true"
android:id="@+id/image_picture"
android:background="#0ff"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable.
But I can hardly understand it.
There are two main keys there, which is crucial to determine what it does
- Adjust the ImageView bounds
- Preserve the aspect ratio of its drawable
The effect of AdjustViewBounds differs when one has a match_parent or wrap_content for the ImageView. Let’s look at each of them separately.
Match Parent ImageView
As we know, this forcing the ImageView to size match up with the Parent’s view…