ConstraintLayout 和 RelativeLayout 的区别 [英] Differences between ConstraintLayout and RelativeLayout

查看:50
本文介绍了ConstraintLayout 和 RelativeLayout 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am confused about the difference between ConstraintLayout and RelativeLayout. Could someone please tell me the exact differences between them?

推荐答案

ConstraintLayout 的目的是通过对每个视图应用一些规则来优化和扁平化布局的视图层次结构以避免嵌套.

Intention of ConstraintLayout is to optimize and flatten the view hierarchy of your layouts by applying some rules to each view to avoid nesting.

Rules 让你想起 RelativeLayout,例如将左侧设置为其他视图的左侧.

Rules remind you of RelativeLayout, for example setting the left to the left of some other view.

app:layout_constraintBottom_toBottomOf="@+id/view1"

RelativeLayout 不同,ConstraintLayout 提供 bias 值,用于根据 0% 和 100% 水平和垂直偏移定位视图相对于手柄(用圆圈标记).这些百分比(和分数)提供了跨不同屏幕密度和尺寸的无缝定位.

Unlike RelativeLayout, ConstraintLayout offers bias value that is used to position a view in terms of 0% and 100% horizontal and vertical offset relative to the handles (marked with circle). These percentages (and fractions) offer seamless positioning of the view across different screen densities and sizes.

app:layout_constraintHorizontal_bias="0.33" <!-- from 0.0 to 1.0 -->
app:layout_constraintVertical_bias="0.53" <!-- from 0.0 to 1.0 -->

基线句柄(圆角长管,在圆形句柄下方)用于将视图的内容与另一个视图引用对齐.

Baseline handle (long pipe with rounded corners, below the circle handle) is used to align content of the view with another view reference.

方形手柄(在视图的每个角上)用于以 dps 为单位调整视图的大小.

Square handles (on each corner of the view) are used to resize the view in dps.

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

This is totally opinion based and my impression of ConstraintLayout

这篇关于ConstraintLayout 和 RelativeLayout 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆