我对 ConstraintLayout
和 RelativeLayout
之间的区别感到困惑。有人可以告诉我它们之间的确切区别吗?
最佳答案
ConstraintLayout
的目的是通过对每个 View 应用一些规则来优化和扁平化布局的 View 层次结构以避免嵌套。
规则类似于 RelativeLayout
,例如将底部边缘设置为其他 View 的底部。
app:layout_constraintBottom_toBottomOf="@+id/view1"
与 RelativeLayout
不同,ConstraintLayout
提供了一个 bias
值,用于以 0% 和 100% 的水平和垂直定位 View 相对于 handle 的偏移量(用红色圆圈标记)。这些百分比(和分数)提供了跨不同屏幕密度和尺寸的无缝 View 定位。
app:layout_constraintHorizontal_bias="0.33" <!-- from 0.0 to 1.0 -->
app:layout_constraintVertical_bias="0.53" <!-- from 0.0 to 1.0 -->
基线句柄(圆角的长管,位于圆形句柄下方)用于将 View 的内容与另一个 View 引用对齐。
方形 handle (在 View 的每个角上)用于以 dps 调整 View 的大小。
这完全是基于意见和我对 ConstraintLayout
关于android - ConstraintLayout 和 RelativeLayout 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37321448/