我很困惑为什么我们需要+
一些同级引用而不是其他引用才能使视图在 android studio 预览窗格中正确呈现。(在正在运行的应用程序中查看时的行为不同,因此不在范围内)
从ID 部分下的 android 指南文档中: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).
来自相对布局参数文档 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"
从相对布局示例:
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>
所有这些信息使我相信该+
符号仅在引用兄弟姐妹时使用,如果兄弟姐妹是在引用之后声明的?
但是,在我的项目中似乎并非如此:
<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>
那么+
符号的规则是什么,我是否错过了任何可靠的文档?