参考文章:https://blog.csdn.net/lmj623565791/article/details/78011599
更详细的用法:https://www.jianshu.com/p/41bd5170cde3
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="#f00"
android:textColor="#0f0"
android:textSize="20sp"
android:text="===="
app:layout_constraintDimensionRatio="H,16:6"/>
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline_h"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.8" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline_w"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.8" />
<TextView
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#ff0"
app:layout_constraintLeft_toRightOf="@id/guideline_w"
app:layout_constraintTop_toBottomOf="@id/guideline_h" />
<!-- <TextView-->
<!-- android:layout_width="50dp"-->
<!-- android:layout_height="50dp"-->
<!-- app:layout_constraintLeft_toLeftOf="parent"-->
<!-- app:layout_constraintRight_toRightOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- app:layout_constraintHorizontal_bias="0.9"-->
<!-- app:layout_constraintVertical_bias="0.9"-->
<!-- android:background="#00f"/>-->
<!-- <TextView-->
<!-- android:id="@+id/tab_first"-->
<!-- android:layout_width="20dp"-->
<!-- android:layout_height="wrap_content"-->
<!-- app:layout_constraintLeft_toLeftOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent"-->
<!-- app:layout_constraintRight_toLeftOf="@+id/tab_second"-->
<!-- android:background="#f00"-->
<!-- app:layout_constraintHorizontal_chainStyle="packed"/>-->
<!-- <TextView-->
<!-- android:id="@+id/tab_second"-->
<!-- android:layout_width="20dp"-->
<!-- android:layout_height="wrap_content"-->
<!-- app:layout_constraintLeft_toRightOf="@+id/tab_first"-->
<!-- app:layout_constraintTop_toTopOf="parent"-->
<!-- app:layout_constraintRight_toLeftOf="@+id/tab_third"-->
<!-- android:background="#ff0"-->
<!-- app:layout_constraintHorizontal_chainStyle="packed"/>/>-->
<!-- <TextView-->
<!-- android:id="@+id/tab_third"-->
<!-- android:layout_width="20dp"-->
<!-- android:layout_height="wrap_content"-->
<!-- app:layout_constraintLeft_toRightOf="@+id/tab_second"-->
<!-- app:layout_constraintRight_toRightOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent"-->
<!-- android:background="#f0f"-->
<!-- app:layout_constraintHorizontal_chainStyle="packed"/>-->
</androidx.constraintlayout.widget.ConstraintLayout>
网友评论