【问题标题】:@ in AndroidManifest.xml file@ 在 AndroidManifest.xml 文件中
【发布时间】:2010-11-04 08:10:07
【问题描述】:

来自 Rick Rogers、John Lombardo、Zigurd Mednieks 和 Blake Meike 合着的 O'Reilly 书籍“Android 应用程序开发”,第 23 页:

 <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />

从第 44 页开始:

 <application android:icon="@drawable/icon2">

上述每个片段中的@是什么意思?

【问题讨论】:

    标签: android xml


    【解决方案1】:

    在这种情况下:

    android:layout_width="fill_parent"
    

    属性值android:layout_width 直接在引号fill_parent 内指定。另一种情况:

    android:text="@string/hello"
    

    属性值android:text="@string/hello" 在别处指定。这由字符串开头的@ 指示。在本例中为@string/hello。该值在资源中。

    来自 Android 开发者网站 The AndroidManifest.xml File 的“资源值”部分。从allclaws 答案中的链接中找到。

    资源值以 以下格式,

    @[package:]type:name

    包名可以省略的地方 如果资源在同一个包中 作为应用程序,类型是一种类型 资源——例如“字符串”或 "drawable" — name 是 标识特定资源。

    【讨论】:

      【解决方案2】:

      我倾向于将其视为与资源所在位置有关的缩写,因此:

      在正常设置中,它会是这样的:

      @drawable/icon = /PROJECT_ROOT/res/drawable/icon.png

      @string/hello = /PROJECT_ROOT/res/values/strings.xml(一个名为“hello”的元素)

      这看起来像是额外的麻烦,但实际上效果很好。它还使对国际化和不同屏幕尺寸的支持变得非常容易。您只需为不同的国家代码和布局声明额外的资源文件,Android 就会为您挑选最佳匹配。

      这份关于internationalization here 的文档可能会让他们更清楚为什么他们决定这样做。

      【讨论】:

        【解决方案3】:
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-01-12
        • 1970-01-01
        • 2022-08-06
        • 2010-11-04
        • 2012-02-23
        • 1970-01-01
        • 2015-02-26
        相关资源
        最近更新 更多