LayoutInflater和inflate()方法的用法 (自定义View中加载xml布局)

来源:互联网 发布:h.323端口号 编辑:程序博客网 时间:2024/05/16 13:49

实现LayoutInflater的实例化共有3种方法,

1 通过SystemService获得

    LayoutInflaterinflater = (LayoutInflater)context.getSystemServices(Context.LAYOUT_INFLATER_SERVICES);
    Viewview = inflater.inflate(R.layout.main, null);

2 从给定的context中获得

    LayoutInflaterinflater = LayoutInflater.from(context);
    Viewview = inflater.inflate(R.layout.mian, null);

3 LayoutInflaterinflater =getLayoutInflater();(在Activity中可以使用,实际上是View子类下window的一个函数)

   Viewlayout = inflater.inflate(R.layout.main, null);


原文:http://www.androidstar.cn/layoutinflater和inflate方法的用法-自定义view中加载xml布局/

0 0
原创粉丝点击