您的位置:首页 > 移动开发 > Android开发

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

2016-12-02 11:36 661 查看
实现LayoutInflater的实例化共有3种方法,

1 通过SystemService获得

    LayoutInflater inflater = (LayoutInflater)context.getSystemServices(Context.LAYOUT_INFLATER_SERVICES);

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

2 从给定的context中获得

    LayoutInflater inflater = LayoutInflater.from(context);

    Viewview = inflater.inflate(R.layout.mian, null);

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

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

原文
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息