android - ConstraintLayout 和 RelativeLayout 的区别

标签 android android-layout android-relativelayout android-constraintlayout

我对 ConstraintLayoutRelativeLayout 之间的区别感到困惑。有人可以告诉我它们之间的确切区别吗?

最佳答案

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 的大小。

enter image description here

这完全是基于意见和我对 ConstraintLayout

的印象

关于android - ConstraintLayout 和 RelativeLayout 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37321448/

相关文章:

android - 工具栏中图标和标题之间的填充/空格 (Android 24)

java - Firebase onDisconnect() 不工作

java - 海量数据android的tablelayout

java - 以编程方式在 fragment 中包含 View 中的布局

android - RelativeLayout,无法解析 id

android - android布局中的背景被拉伸(stretch)

java - 如何将 DateTimeFormatter 包含到项目中

android - 如何在android中设置图像背景和文本/图像

android - 访问 Java 文件中的 Android View

android - Gradle 同步失败,出现 "Could not resolve dependency"错误