ConstraintLayout weird attributes behavior when constraining 2 views

会有一股神秘感。 提交于 2019-12-11 17:38:51

问题


Let's say that I want to connect one view to another with app:layout_constraintTop_toTopOf (it can be any other constraint).

If I will do it manually from the XML display it will be something like this:

 app:layout_constraintTop_toTopOf="@id/something"

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.

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 +.


回答1:


The +id is only needed the first time an id is mentioned in the xml.

It can still be useful to have the + every time in case you want to reorder the xml in the future.

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.)



来源:https://stackoverflow.com/questions/55536227/constraintlayout-weird-attributes-behavior-when-constraining-2-views

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!