什么是之间和的差额QUOT;安卓?"和" @android:"在Android的布局XML文件? [英] What's the difference between "?android:" and "@android:" in an android layout xml file?

查看:119
本文介绍了什么是之间和的差额QUOT;安卓?"和" @android:"在Android的布局XML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是之间的区别在Android的布局XML文件机器人:?:和@android?他们似乎是重复使用Android SDK中的资源互换的方式。

What's the difference between "?android:" and "@android:" in an android layout xml file? They seem to be interchangeable ways of reusing android SDK resources.

我发现的唯一的差异是由以下例子所示。

The only difference I discovered is illustrated by the following example.

下面TextView的的右边缘与所述的ImageButton的左边缘对齐呈现

Here the TextView's right edge is rendered aligned with the left edge of the 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。

Here, however, the right edge of the TextView is aligned with the right edge of the RelativeLayout. The TextView overlaps the 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 VS?机器人。双方没有错误编译。

The only difference between the two layouts is the use of @android vs ?android. Both compile with no errors.

谢谢了。

推荐答案

prefixing带有问号的号码表示要访问硬编码的属性,它是在一个风格的主题定义的样式属性,而不是

Prefixing the ID with a question mark indicates that you want to access a style attribute that's defined in a style theme, rather than hard-coding the attribute.

请参阅引用样式属性在这里:<一href="http://developer.android.com/guide/topics/resources/accessing-resources.html#ReferencesToThemeAttributes">accessing-resources

See "Referencing Style Attributes" here: accessing-resources

这篇关于什么是之间和的差额QUOT;安卓?&QUOT;和&QUOT; @android:&QUOT;在Android的布局XML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆