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()。系统提供的解析服务。

  • 相关阅读:
    连续时间单位冲激信号δ(t)的基本性质
    数据结构练习
    数据结构练习
    数据结构练习
    使用 matplotlib 绘制带日期的坐标轴
    数据结构练习
    c++ primer 练习10.33_p363
    C++迭代器之'插入迭代器
    C++ 11 Lambda表达式
    《C++ Primer》读书笔记—第十章 泛型算法
  • 原文地址:https://www.cnblogs.com/mamamia/p/7883236.html
Copyright © 2011-2022 走看看