• LayoutInflater


    LayoutInflater : 一个抽象类, 作用类似于findViewById

    • layoutInflater 用来找res/layout 下的xml文件, 并且实例化
    • findViewById 用来找xml文件中的控件

    作用:

    • layoutInflater 对于一个没有被载入 或者 想要动态载入的界面,都需要使用LayoutInflater.inflater来载入
    • 对于一个已经载入的界面,可以通过Activity.findViewById方法获取其中的控件元素

    获取layoutInflater:    本质都是调用Context.getSystemService()

    • LayoutInflater inflater = getLayoutInflater();
    • LayoutInflater inflater = LayoutInflater.from(context);
    • LayoutInflater inflater = LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    加载ContextImpl时会将 LayoutInflater的ServiceFetcher注入到容器中。

    PhoneLayoutInflater 继承自 LayoutInflater 

    作用: 根据传入的view获取view的类完整路径,根据类的完整路径来构造对应的view对象

    Activity 中的setContentView方法实际上调用的是Window的setContentView,而Window是抽象类,其具体实现类为PhoneWindow

  • 相关阅读:
    开启Spring Boot 之旅
    Java笔试面试练习题---集合
    Python
    Python
    Redis -下载与基本使用
    Git
    Vue全家桶-Vue-router&Vuex
    Es6
    Vue-前端
    Django基础及实战
  • 原文地址:https://www.cnblogs.com/acg88688/p/11913339.html
Copyright © 2020-2023  润新知