ConstraintLayout和RelativeLayout之间的区别 [英] Differences between ConstraintLayout and RelativeLayout
问题描述
我对ConstraintLayout
和RelativeLayout
之间的区别感到困惑.有人可以告诉我他们之间的确切区别吗?
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.
规则使您想起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屋!