zoukankan      html  css  js  c++  java
  • LayoutInflater 三种获得方式

    LayoutInflater 作用是从外部加载一个xml布局文件。

    获得 LayoutInflater 实例的三种方式:

    1.LayoutInflater inflater = getLayoutInflater();  //调用Activity的getLayoutInflater()

    2.LayoutInflater localinflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    3. LayoutInflater inflater = LayoutInflater.from(context)

    分析:

    getLayoutInflater():

    Activity 中 getLayoutInflater() 调用 PhoneWindow 的getLayoutInflater()方法

    public PhoneWindow(Context context) {         

       super(context);         

       mLayoutInflater = LayoutInflater.from(context); 

     }

    最后调用 LayoutInflater.from(context)。

    LayoutInflater.from(context):

    public static LayoutInflater from(Context context) {      

       LayoutInflater LayoutInflater =  (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);       

       if (LayoutInflater ==null) {          

           throw new AssertionError("LayoutInflater not found.");      

       }      

       return LayoutInflater;  

     }

    其实最后者是调 context.getSystemService()。系统提供的解析服务。

  • 相关阅读:
    Windows 10 将MySQL5.5升级为MySQL5.7
    Django Rest Swagger生成api文档
    inception安装使用
    django 日志配置
    构建NTP时间服务器
    django 模型关系
    python 开发环境配置
    mongodb远程备份
    rest framework 尝鲜
    Django Rest Framework-介绍
  • 原文地址:https://www.cnblogs.com/mamamia/p/7883236.html
Copyright © 2011-2022 走看看