[Android studio] 第15节 ConstraintLayout控件

ConstraintLayout 是 Android 中的布局容器,它是一个灵活且强大的布局工具,用于创建复杂的界面布局。它通过使用约束(constraints)来定义子视图之间的关系和对齐方式。

以下是 ConstraintLayout 常用的属性:

  1. app:layout_constraintTop_toTopOf:将子视图的顶部与指定视图的顶部对齐。
  2. app:layout_constraintBottom_toBottomOf:将子视图的底部与指定视图的底部对齐。
  3. app:layout_constraintStart_toStartOf:将子视图的起始端与指定视图的起始端对齐。
  4. app:layout_constraintEnd_toEndOf:将子视图的结束端与指定视图的结束端对齐。
  5. app:layout_constraintLeft_toLeftOf:将子视图的左侧与指定视图的左侧对齐。
  6. app:layout_constraintRight_toRightOf:将子视图的右侧与指定视图的右侧对齐。
  7. app:layout_constraintTop_toBottomOf:将子视图的顶部与指定视图的底部对齐。
  8. app:layout_constraintBottom_toTopOf:将子视图的底部与指定视图的顶部对齐。
  9. app:layout_constraintStart_toEndOf:将子视图的起始端与指定视图的结束端对齐。
  10. app:layout_constraintEnd_toStartOf:将子视图的结束端与指定视图的起始端对齐。
  11. app:layout_constraintHorizontal_bias:设置子视图在水平方向上的偏移值。
  12. app:layout_constraintVertical_bias:设置子视图在垂直方向上的偏移值。
  13. app:layout_constraintWidth_percent:设置子视图的宽度占父视图宽度的百分比。
  14. app:layout_constraintHeight_percent:设置子视图的高度占父视图高度的百分比。
  15. app:layout_constraintDimensionRatio:设置子视图的宽高比。
  16. app:layout_constraintHorizontal_chainStyle:设置多个子视图水平排列时的链样式。
  17. app:layout_constraintVertical_chainStyle:设置多个子视图垂直排列时的链样式。
  18. app:layout_constraintGuide_percent:创建一个指定百分比位置的辅助线。
  19. app:layout_constraintBaseline_toBaselineOf:将子视图的基线与指定视图的基线对齐。
  20. app:layout_constraintCircle:将子视图放置在指定视图的圆周上。

这些属性可以通过设置在 ConstraintLayout 的子视图上,以定义它们之间的关系和对齐方式,从而创建灵活且响应式的界面布局。您可以根据需要选择适当的属性进行配置。

猜你喜欢

转载自blog.csdn.net/AA2534193348/article/details/131476931