由"@id/myid"引发的一场血案

本文探讨了Android开发中ids.xml与public.xml的作用及优缺点。ids.xml通过减少R.java重复生成提升编译效率,而public.xml则允许开发者自定义资源ID,便于换肤功能实现及多模块开发。
今天反编译了某个应用,再一次的发现了,ids.xml和public.xml文件。之前有了解过相关的知识,但是仅限于一下某些“似是”的了解,这样挺危险的,故写下这段文字来做一个深入研究的第一步。

1、粗浅的认知:
使用ids.xml可能带来的好处,"@id"比"@+id"的编译速度要快,因为只要在R.java生成一次对应值之后,便不会再次生成;最大的好处可能还是支持public.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item type="id" name="profiles_qqweibo_v_icon" />
    <item type="id" name="navbar_layout">false</item>
</resources>
使用public.xml可能带来的好处,可以控制生成资源文件的"唯一标识",可能使换肤类功能更易实现,或者另一方面可支持一个项目使用多工程分模块开发的形式? 弊端则是太麻烦。
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <public type="attr" name="adapterViewBackground" id="0x7f010000" />
    <public type="string" name="follow_err_limited" id="0x7f0c00e4" />
    <public type="style" name="PapaPreferenceTheme" id="0x7f0d0015" />
    <public type="color" name="pull_to_refresh_text_color" id="0x7f08000a" />
    <public type="id" name="viewpager_layout" id="0x7f07012a" />
</resources>
2、可参考:
What is the use of the res/values/public.xml file on Android?

Difference between “@id/” and “@+id/” in Android



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值