安卓除了有6种最基本的布局线性布局(LinearLayout)、相对布局(RelativeLayout)、帧布局(FrameLayout)、网格布局(GridLayout)、绝对布局(AbsoluteLayout)、表格布局(TableLayout)外还有一些较复杂的布局,如ConstraintLayout。 1、优点 调整控件的位置和大小时更加灵活,功能更强大。 2、继承关系 和其他布局一样继承自ViewGroup。 3、新特性 相对定位: <Button android:id="@+id/buttonA" ... /> <Button android:id="@+id/buttonB" ... app:layout_constraintLeft_toRightOf="@+id/buttonA" /> 按钮b的右对齐按钮a

  • layout_constraintLeft_toLeftOf // 左边左对齐
  • layout_constraintLeft_toRightOf // 左边右对齐
  • layout_constraintRight_toLeftOf // 右边左对齐
  • layout_constraintRight_toRightOf // 右边右对齐
  • layout_constraintTop_toTopOf // 上边顶部对齐
  • layout_constraintTop_toBottomOf // 上边底部对齐
  • layout_constraintBottom_toTopOf // 下边顶部对齐
  • layout_constraintBottom_toBottomOf // 下边底部对齐
  • layout_constraintBaseline_toBaselineOf // 文本内容基准线对齐
  • layout_constraintStart_toEndOf // 起始边向尾部对齐
  • layout_constraintStart_toStartOf // 起始边向起始边对齐
  • layout_constraintEnd_toStartOf // 尾部向起始边对齐
  • layout_constraintEnd_toEndOf // 尾部向尾部对齐 外边距: <android.support.constraint.ConstraintLayout ...> <Button android:id="@+id/button" ... app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent/> <android.support.constraint.ConstraintLayout/> 空间居中效果 倾向: <android.support.constraint.ConstraintLayout ...> <Button android:id="@+id/button" ... app:layout_constraintHorizontal_bias="0.3" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent/> <android.support.constraint.ConstraintLayout/> 左边占0.3,右边占0.7 可见性的表现: 尺寸约束: android:minWidth 设置布局的最小宽度 android:minHeight 设置布局的最小高度 CHAIN: 辅助工具: