"?android:"和"@android:"在Android布局xml文件中有什么区别?它们似乎是重用Android SDK资源的可互换方式。
我发现的唯一区别如下所示。
在这里,TextView的右边缘与ImageButton的左边缘对齐。
<RelativeLayout
android:id="@id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#888888">
<TextView
android:id="@android:id/text1"
android:layout_alignParentLeft="true"
android:text="blah blah"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@android:id/button1" />
<ImageButton
android:id="@android:id/button1"
android:layout_alignParentRight="true"
style="@style/PlusButton" />
</RelativeLayout>
然而,在这里,TextView的右边缘与RelativeLayout的右边缘对齐。TextView会覆盖ImageButton。
<RelativeLayout
android:id="@id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#888888">
<TextView
android:id="@android:id/text1"
android:layout_alignParentLeft="true"
android:text="blah blah"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="?android:id/button1" />
<ImageButton
android:id="?android:id/button1"
android:layout_alignParentRight="true"
style="@style/PlusButton" />
</RelativeLayout>
这两种布局之间唯一的区别是使用了@android和?android。它们都可以编译通过,没有错误。
非常感谢。