Jul*_* A. 42 layout android reference
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>
Run Code Online (Sandbox Code Playgroud)
但是,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>
Run Code Online (Sandbox Code Playgroud)
两种布局之间的唯一区别是使用@android vs?android.两者都编译没有错误.
非常感谢.
Jas*_*run 36
使用问号前缀ID表示您要访问在样式主题中定义的样式属性,而不是对属性进行硬编码.
请参阅此处的"引用样式属性":access-resources
归档时间: |
|
查看次数: |
10653 次 |
最近记录: |