Поместите ImageView
в ConstraintLayout
. Это даст ImageView доступ к app:layout_constraintDimensionRatio
, где вы можете указать желаемое соотношение.
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constrainedHeight="true"
app:layout_constrainedWidth="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="183:124"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Вы также можете сделать это программно:
imageView.updateLayoutParams<ConstraintLayout.LayoutParams> {
dimensionRatio = "183:70"
}