Tamir Abutbul
Tamir Abutbul

Reputation: 7651

ConstraintLayout weird attributes behavior when constraining 2 views

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

Upvotes: 0

Views: 60

Answers (1)

Rasmusob
Rasmusob

Reputation: 508

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

Upvotes: 2

Related Questions