在launcher开发中,我们老大做了一个插件化的酷生活。可以在原生launcher的基础上方便的一页(-1屏)。显示一些常用应用,服务,和新闻。如下图:
这一页整个是一个view,添加在celllayout中,然后把这个celllayout添加在workspace里就好了。
private void initCustomPage( CellLayout cell ) { if( hasCustomContent() ) { try { mCustomPageView = FavoritesPageManager.getInstance( this.getContext() ).getView(); if( mCustomPageView != null ) { cell.addView( mCustomPageView ); cell.setCustomPage( true ); } } catch( Exception e ) { e.printStackTrace(); } } }
plugin单独编译一个apk,放在宿主apk的assets目录。宿主apk运行时,调用初始化方法,动态的加载plugin.apk的代码和资源。(老大说用到了什么classLoader,小白表示不是很懂)
给客户移植的过程中遇到问题了,导致客户launcher一起重启。后来发现是plugin.apk自动生成的R文件和客户launcher.apk自动生成的R文件中id有冲突导致。
作为一个爱学习的程序猿,遇到问题当然是上网求答案。经过一番查找,终于找到几种方法:
layout文件
<TextView android:id="@id/textView15" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:paddingBottom="@dimen/icon_padding_top" android:text="TextView" />
values下面新建的ids.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <!-- //****** add whole file //解决“launcher3的R文件中id和酷生活R文件中id冲突”的问题 --> <item type="id" name="textView15" /> </resources>
values下面新建的ids.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <!-- //****** add whole file //解决“launcher3的R文件中id和酷生活R文件中id冲突”的问题 --> <public-padding name="zmap" start="0x7f030000" end="0x7f030fff" type="id"/> </resources> 效果:在自动生成的R文件中可以看到,所有的id都在start和end之间
name:随意取一个名字。
start/end:起始位置/终止位置
type:id 或者其他资源
ps:第一篇博客,写的不好,多多包涵。