约束2个视图时,ConstraintLayout怪异的属性行为 [英] ConstraintLayout weird attributes behavior when constraining 2 views
问题描述
假设我要使用app:layout_constraintTop_toTopOf
将一个视图连接到另一个视图(可以是任何其他约束).
Let's say that I want to connect one view to another with app:layout_constraintTop_toTopOf
(it can be any other constraint).
如果我将通过XML显示手动进行操作,则将如下所示:
If I will do it manually from the XML display it will be something like this:
app:layout_constraintTop_toTopOf="@id/something"
但是-如果我使用设计选项而不是XML选项做同一件事,由于某种原因,我将获得额外的+
(自动生成)字符它看起来像这样:
But - If I will do the same thing with the design option and not the XML option I will get extra +
(auto generated) char for some reason and it will look like this :
//notice the extra + in @+id
app:layout_constraintTop_toTopOf="@+id/something"`
现在有趣的是,该应用程序可以在带有或不带有+字符的情况下运行.
Now the funny thing is that the app will run with or without the + char.
所以-看起来我在引用其他视图时确实不需要多余的+字符,我的问题是为什么正在发生,并且如何我可以防止android工作室布局编辑器中添加此+.
So - looks like I don't really need that extra + char while referring to other views, my question is why this is happening and how can I prevent android studio layout editor to add this +.
推荐答案
仅在xml中第一次提及ID时才需要+ id.
The +id is only needed the first time an id is mentioned in the xml.
每次以后都要使用+还是很有用的,以防将来要对xml重新排序.
It can still be useful to have the + every time in case you want to reorder the xml in the future.
我对此不会太担心.进行+ id可能会大大降低构建时性能. (看看您是否可以衡量差异.我怀疑您可以.)
I would not worry too much about this. Doing +id likely has an extremely low build-time performance hit. (See if you can measure the difference. I doubt you can.)
这篇关于约束2个视图时,ConstraintLayout怪异的属性行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!