1

In a relative layout I see a pattern as:

<TextView 
    android:id=“@+id/txt_id”
    etc
   android:layout_alignBottom="@+id/some_other_txt”
    etc
/>

<TextView
 android:id="@+id/some_other_txt"

 etc
/>

I thought +id is used only when creating an id for a widget. Is this a kind of “trick” to layout a widget relative to another widget declared later in the file?

UPDATE:
This question is specifically about the RelativeLayout possitioning. Not about the difference in syntax in general as the linked question

Jim
  • 18,826
  • 34
  • 135
  • 254
  • 2
    You reference a View **anticipately** (a View which hasn't yet been created in the xml) by using `@+id`. But I prefer creating the View **before** and then refer it by using `@id`. – Phantômaxx Mar 30 '15 at 15:17
  • @DiegoFreniche:I think there is no duplicate. My question is about RelativeLayout and not in general the difference between the syntax – Jim Mar 30 '15 at 15:18
  • @DerGolem:Is this somewhere documented? I could not find it somewhere – Jim Mar 30 '15 at 15:19
  • Oh, now you are asking too much... I can't remember where did I get this bit of info. Maybe, from a book. – Phantômaxx Mar 30 '15 at 15:22
  • In RelativeLayout the order in which you write your widgets it's not the same as they appear on screen. Android Lint needs to check all relationships too, so maybe this is a way to avoid Lint from giving you warnings – Diego Freniche Mar 30 '15 at 15:24
  • @DerGolem:I am asking in the sense I could not even google about this trick – Jim Mar 30 '15 at 15:24
  • This pdf is in French, but you can always use Google Translate... http://cedric.cnam.fr/~farinone/SETMO/seance2PourSETMO.pdf - Search `@+id > @id` – Phantômaxx Mar 30 '15 at 15:26

2 Answers2

0

Its just a reference point for placing the different elements in the layout builder.

0

From this SO answer

The first time you reference an ID, use the @+ prefix, which tells the resource builder to add the ID,

Here you're making a forward reference to a widget & id that's not already defined:

<TextView 
    android:id=“@+id/txt_id”
    etc
   android:layout_alignBottom="@+id/some_other_txt”
    etc
/>

Here you are defining it:

<TextView
 android:id="@+id/some_other_txt"

More context here

Community
  • 1
  • 1
Diego Freniche
  • 5,225
  • 3
  • 32
  • 45