Set layout_constraintDimensionRatio in the code:
ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(mRlContent);
constraintSet.setDimensionRatio(R.id.iv,"h,9:16");
constraintSet.applyTo(mRlContent);
Copy the code
Corresponding layout:
<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>
Copy the code
Reference: www.jianshu.com/p/16e34f919…