呆瓜小董 2021-11-11 11:21 采纳率: 84.6%
浏览 18
已结题

getlayoutinflater().from(this).inflate 和 View.inflate的区别是什么

最近学习安卓基础发现同一个需求不同视频里用的方法不一样,有的用getlayoutinflater().from(this).inflate ,有的用View.inflate,想知道这两个方法有什么区别

  • 写回答

1条回答 默认 最新

  • pumpkin的玄学 2021-11-11 12:41
    关注

    你说的是 LayoutInflater.from(context).inflate 吧
    其实View.inflate里面间接调用了 LayoutInflater.from(context).inflate
    给你看一下View.inflate的源码

        public static View inflate(Context context, @LayoutRes int resource, ViewGroup root) {
            LayoutInflater factory = LayoutInflater.from(context);
            return factory.inflate(resource, root);
        }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 12月8日
  • 已采纳回答 11月30日
  • 创建了问题 11月11日