I'm confused about why we need the +
in some sibling references but not others to make views render correctly in the android studio preview pane. (The behaviour when viewing in a running app differs, so is not in scope)
From the android guide docs under the ID section: The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R.java file).
From the Relative Layout Params docs android:layout_toLeftOf
Positions the right edge of this view to the left of the given anchor view ID. May be a reference to another resource, in the form "@[+][package:]type/name"
From Relative Layout Examples :
In your XML layout, dependencies against other views in the layout can be declared in any order. For example, you can declare that "view1" be positioned below "view2" even if "view2" is the last view declared in the hierarchy. The example below demonstrates such a scenario.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/reminder" />
<Spinner
android:id="@+id/dates"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_below="@id/name" <- no + as 'name' already declared?
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/times" /> <- + present as times not declared yet?
<Spinner
android:id="@id/times"
android:layout_width="96dp"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:layout_alignParentRight="true" />
<Button
android:layout_width="96dp"
android:layout_height="wrap_content"
android:layout_below="@id/times"
android:layout_alignParentRight="true"
android:text="@string/done" />
</RelativeLayout>
All this info leads me to believe that the +
symbol is only used when referencing siblings, if the sibling is declared after the reference?
However this doesn't appear to be the case in my project:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_grey_light"
android:paddingBottom="10dp">
<ImageView
android:id="@+id/img"
android:layout_width="match_parent"
android:layout_height="220dp"
android:adjustViewBounds="true" />
<TextView
android:id="@+id/some_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/img" <- This needs a + to render correctly..
android:text="@{some.name}"/>
</RelativeLayout>
So what is the rule for the +
symbol, and is there any solid documentation that i've missed?