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

查看:39
本文介绍了我什么时候应该使用资产而不是 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.

一个.您可以在 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 (res) 的子文件夹,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天全站免登陆