Reputation: 4068
I have a listview of the images of different sizes. Images are loaded using glide library.
Currently I have set the height and width of the imageview as wrap_content to get the original feel of the image, but it's not behaving properly.
Therefore I want to set imageview width and height using aspect ratio.
I have used different scaleType, but not getting desired result.
Any help is appreciated
Upvotes: 1
Views: 431
Reputation: 10971
I would suggest you use the DimensionConstraints from ConstraintLayout. You can define an aspect ratio using the app:layout_constraintDimensionRatio attribute, so your ImageView can be something like this:
<ImageView android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="H,2:1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
So the image view height will always be half the value of the width.
Upvotes: -1