关于我的android项目中如何不使用资源的几个问题
我的 Android 项目旨在作为可重用库(如 jar)进行分发。我的理解是我不能使用任何资源(没有对静态 R 类的引用)。我有几个关于如何执行此操作的问题。
处理可绘制对象的好方法是什么?如果我在 /images/image.png 的源路径中包含图像,那么我可以使用以下代码加载它。这是一个好的策略吗?
InputStream is = getClass().getResourceAsStream("/images/image.png");
BitmapFactory.decodeStream(is);
我该如何应对国际化?我想我可以将所有字符串包含到一个 Java 类中,然后根据设备的语言返回一个字符串。但是,这会对我的应用程序造成内存负担吗?另外,确定设备语言的正确方法是什么?
My Android project is intended to be distributional as a reusable library, as a jar. My understanding is that I can not use any resources (no references to the static R class). I have a couple of questions about how to do this.
What is a good way to handle drawables? If I include an image on my sourcepath at /images/image.png then I can load it with the below code. Is this a good strategy?
InputStream is = getClass().getResourceAsStream("/images/image.png");
BitmapFactory.decodeStream(is);
How should I handle internationalization? I guess I could include all my strings into a Java class and than return one based on the device's language. But, would this be a memory burden on my app? Also, what is the proper way to determine the device's language?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有什么理由将它作为罐子分发吗?我建议您将其作为图书馆项目分发。 此处描述的 Android 库项目将允许您使用静态R 类的使用方式与在普通项目中使用它的方式相同,并且您也将有能力处理国际化。
使用库项目的一个很好的理由是,放置在 res/ 文件夹中的资源在编译时被严重压缩,以减少二进制文件的最终大小。对于图像和 xml 文件都是如此。
Is there any reason for distributing it as a jar? I would advice you to distribute it as a Library Project instead. Android Library Projects, described here, will let you use the static R class the same way you use it in a normal project, and you will have the ability to handle internationalization as well.
A very good reason for using a library project is the fact that resources placed in the res/ folder are heavily compressed compile-time to decrease the final size of you binary. This is true both for images and xml files.