Issue
I'm using an ImageView
in an Android project.
Width: match_parent
Height: wrap_content
then I scale it to fill_XY
, but the image is not square yet... what can I do?
src="https://i.stack.imgur.com/r4bnd.png" alt="enter image description here" />
Solution
The best way for square image is use ConstraintLayout with constraintDimensionRatio Without give fix height/width.
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="H,1:1"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Answered By - PriyankVadariya
Answer Checked By - Pedro (JavaFixing Volunteer)