Android: Keep Ratio For A Full-width And Undefined Height Imageview In A Constraintlayout?
In a ConstraintLayout, an ImageView is bound to its parent in such a way that: Its left side is bound to the screen's left side Its right side is bound to the screen's right side
Solution 1:
In addition to the last answer, the reason your image is not being scaled properly is because you are using it as the background.
Your code..
android:background="@drawable/ic_background_stars"
Instead, use it as image resource.
app:srcCompat="@drawable/ic_background_stars"
And the default scale type of ImageView should do the work for you. Else, you can even experiment with various scale types.
Solution 2:
I think that you can use app:layout_constraintDimensionRatio="your ratio"
to keep the aspect ratio if your image
For example, if you want square you need the same width and height so use - app:layout_constraintDimensionRatio="1:1"
Post a Comment for "Android: Keep Ratio For A Full-width And Undefined Height Imageview In A Constraintlayout?"