相关疑难解决方法(0)

android布局xml文件中"?android:"和"@android:"之间有什么区别?

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.两者都编译没有错误.

非常感谢.

layout android reference

42
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

layout ×1

reference ×1