将 resourceId 分配给 Android 中的布局

Assign resourceId to Layout in Android

据我了解以下内容。

A resource ID is a 32 bit number of the form: PPTTNNNN. PP is the package the resource is for; TT is the type of the resource; NNNN is the name of the resource in that type. For applications resources, PP is always 0x7f.

示例:

aapt 按此顺序处理的这些资源文件:

layout/main.xml
drawable/icon.xml
layout/listitem.xml

我们看到的第一种类型是 layout,所以给出的是 TT == 1。该类型下的第一个名字是“main”,因此给出 NNNN == 1。最终资源 ID 为 0x7f010001.

接下来我们看到 drawable 所以给出 TT == 2。该类型的第一个名称是“icon”,因此得到 NNNN == 1。最终资源 ID 为 0x7f020001.

最后我们看到另一个 layout 和以前一样有 TT == 1。它有一个新名称 listitem,以便获得下一个值 NNNN == 2。最终资源 ID 为 0x7f010002.

问题:

但是最近我看到一些布局文件是通过以下方式分配ID的。

java代码

 this.f5160k = (ImageView) findViewById(2131755224);
 this.f5163n = findViewById(2131755219);
 this.f5162m = (LinearLayout) findViewById(2131755223);
 this.f5161l = (LinearLayout) findViewById(2131755220);
 this.f5158i = (GridView) findViewById(2131755222);

正如我所知,第一部分 this.f5160k 是声明,但这种格式是什么 2131755224。任何人都可以给我建议或知识吗? ?

21317552240x7F1000D8

的十进制表示

在您分享的代码中,开发人员决定对十进制数字进行硬编码,而不是使用十六进制格式。但是,两者具有相同的值并指向相同的 resourceID。

您可以选择使用 21317552240x7F1000D8

在R.java中,您可以找到十六进制格式的ID。

这些大数字只是 0x7f.. 格式数字的十进制表示(顺便说一下,这是十六进制)。

 long n = 2131755224;
 System.out.println(Long.toHexString(n));  

输出:7f1000d8

2131755224 == 0x7F1000D8 将 return true.