【发布时间】:2011-01-23 01:58:28
【问题描述】:
android布局xml文件中的“?android:”和“@android:”有什么区别?它们似乎是复用 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 的使用。两者都编译没有错误。
非常感谢。
【问题讨论】: