LayoutInflater 是否每次加载 View 时都加载 xml 布局资源?
View view = LayoutInflater.from(context).inflate(R.layout.resource, null);
例如,如果我想创建 100 个具有相同布局 ID 的 View ,它会解析 100 次相同的 XML 文件还是有一些 android 框架的缓存系统?
最佳答案
当您查看 inflate 代码流时,您可以看到显然使用了多个缓存:
我首先看到:
View view = tryInflatePrecompiled(resource, res, root, attachToRoot);
然后在ResourceImpl XmlResourceParser loadXmlResourceParser
中另一个缓存
@NonNull
XmlResourceParser loadXmlResourceParser(@NonNull String file, @AnyRes int id, int assetCookie,
@NonNull String type)
throws NotFoundException {
if (id != 0) {
try {
synchronized (mCachedXmlBlocks) {
final int[] cachedXmlBlockCookies = mCachedXmlBlockCookies;
final String[] cachedXmlBlockFiles = mCachedXmlBlockFiles;
关于android - LayoutInflater是不是每次都加载xml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12525345/