ImageView – have height match width?

Updated July 28 2021 to use AndroidX instead of the support library

First, make sure your project has AndroidX imported, by following the directions here.

Then wrap your image inside a ConstraintLayout, and its fields as such:

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        app:layout_constraintDimensionRatio="1:1" />

</androidx.constraintlayout.widget.ConstraintLayout>

See here

Leave a Comment