美文网首页
assets与res/raw的区别

assets与res/raw的区别

作者: jiangjh | 来源:发表于2017-12-01 21:43 被阅读0次

    src/main/assets vs src/main/res/raw 的相同点与不同点

    • 相同点

      不会被编译成二进制文件,会原样拷贝到apk中。

    • 不同点
      • asset下的文件不会被映射到R文件中(无法引用资源),但可以有目录结构
      • raw下的文件会被映射到R文件中(可用R.raw.xxx引用资源),但不能有目录结构

    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 an 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.

    The Assets folder is an “appendix” directory. The R class does not generate IDs for the files placed there, so its less compatible with some Android classes and methods. Also, it’s much slower to access a file inside it, 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.

    [参考链接]
    The reason for Assets and Raw Resources in Android

    相关文章

      网友评论

          本文标题:assets与res/raw的区别

          本文链接:https://www.haomeiwen.com/subject/rkcgbxtx.html