How would I go implementing a fixed aspect ratio View
? I\'d like to have items with 1:1 aspect ratio in a GridView
. I think it\'s better to subclas
You may find third-party libraries. Instead of using them, use constraint layout. Below code sets the aspect ratio of ImageView as 16:9 regardless of the screen size and orientation.
app:layout_constraintDimensionRatio="H,16:9"
. Here, height is set with respect to the width of the layout.
For your question, set android:layout_width="match_parent"
and use app:layout_constraintDimensionRatio="H,1:1"
in your view.