🧩 Guideline 用法说明
<androidx.constraintlayout.widget.Guideline
android:id="@+id/glVerticalGuideStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="30dp" />
这段代码是使用 ConstraintLayout 中的一个特殊布局组件 —— Guideline,它并不是一个实际可见的视图,而是一个辅助布局用的虚拟参考线,可以帮助你对其他控件进行约束定位。
🧾 各属性含义如下:

截屏2025-05-29 11.56.17.png
📌 实际用途示例
比如,你想让一个 TextView 靠着这条参考线对齐:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello Guideline"
app:layout_constraintStart_toStartOf="@id/glVerticalGuideStart"
app:layout_constraintTop_toTopOf="parent" />
此时这个 TextView 的左边将对齐到这条垂直参考线(也就是距离左边 30dp 的位置)。
🛠️ Guideline 的三种定位方式:

截屏2025-05-29 11.57.01.png
🎯 使用 Guideline 的典型场景
• 在 ConstraintLayout 中模仿栅格布局(比如 30%、60%、10% 的左右划分)
• 使多个控件 在不同位置保持整齐对齐
• 响应式布局(例如,随屏幕宽度变化自动调整位置)