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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…