匿名用户
将ImageView放置在ConstraintLayout中。 这将授予ImageView访问app:Layout_ConstraintDimensionRatiane的权限,您可以在其中指定所需的比率。
android:layout_width="match_parent"
android:layout_height="wrap_content">
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"/>
您也可以通过编程方式实现此操作:imageView.updateLayoutParams {
dimensionRatio = "183:70"
}