代码中设置layout_constraintDimensionRatio:
ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(mRlContent);
constraintSet.setDimensionRatio(R.id.iv,"h,9:16");
constraintSet.applyTo(mRlContent);
对应布局:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/iv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@null"
app:layout_constraintTop_toTopOf="parent"
tools:background="@drawable/ic_launcher" />
...
</androidx.constraintlayout.widget.ConstraintLayout>