什么时候应该使用资产而不是Android中的原始资源? [英] When should I use the assets as opposed to raw resources in Android?

查看:101
本文介绍了什么时候应该使用资产而不是Android中的原始资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Android,但是我只介绍了Assets和Raw资源.我试图了解使用原始资源与资产的原因.

I'm in the mid of my Android studies, and I just covered the Assets and Raw resources. I'm trying to understand the reason for using Raw resources vs. Assets.

  1. 它们都提供了未编译的资源输入流.

  1. They both provide with an uncompiled resource input stream.

资产似乎比原始资源提供了更多的灵活性和功能.

It seems that Assets provide much more flexibility and functionality than Raw resources.

a.您可以在assets下创建文件夹结构,但不能在raw

a. You can create folder structures under assets but not under raw

b.您可以在assets文件夹中动态列出所有资源,但不能在raw文件夹中列出.

b. You can list all resources dynamically in the assets folder but not in the raw folder.

那么,为什么我要在Android中使用Raw资源?

So, why would I use Raw resources in Android?

推荐答案

raw文件夹和assets文件夹之间的主要区别.

The main differences between the raw folder and the assets folder.

  • 由于raw是Resources(资源)的子文件夹,因此Android将 自动为其中的任何文件生成ID.这 然后将ID存储在R class中,该参考将用作 一个文件,意味着可以从其他Android类轻松访问该文件 和方法,甚至在Android XML文件中.自动使用 生成的ID是访问Android中文件的最快方法.

  • Since raw is a subfolder of Resources (res), Android will automatically generate an ID for any file located inside it. This ID is then stored in the R class that will act as a reference to a file, meaning it can be easily accessed from other Android classes and methods and even in Android XML files. Using the automatically generated ID is the fastest way to have access to a file in Android.

assets文件夹是附录" 目录. R类可以 不会为放置在那里的文件生成ID 一些Android类和方法. assets文件夹中的文件访问较慢,因为您需要获取该文件的句柄 基于字符串.但是,某些操作更容易通过 将文件放在此文件夹中,例如将数据库文件复制到 系统的内存.没有(简单)的方法来创建Android XML 引用Assets文件夹中的文件.

The assets folder is an "appendix" directory. The R class does not generate IDs for the files placed there, which is less compatible with some Android classes and methods. File access in the assets folder is slower since you will need to get a handle to it based on a String. However some operations are more easily done by placing files in this folder, like copying a database file to the system’s memory. There’s no (easy) way to create an Android XML reference to files inside the Assets folder.

这篇关于什么时候应该使用资产而不是Android中的原始资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆