`
朱润泽
  • 浏览: 46419 次
  • 性别: Icon_minigender_1
  • 来自: 江西
社区版块
存档分类
最新评论

LayoutInflater初识

阅读更多

LayoutInflaterAPI的介绍中可以知道,该类是主要用于对XML文件的转化成一个响应的视图对象的类。应用该功能之前还需声明一个LayoutInflater工厂对象。有三种方法可以使用:

1、LayoutInflater  factory  = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

2、LayoutInflater  factory  = (LayoutInflater)LayoutInflater.from(context);

3、LayoutInflater  factory = (LayoutInflater)context.getLayoutInflater();

其中:context是对应的Activity类名。

      方法2中调用了方法1

      方法3中不太清楚实现细节。知道的可以赐教。

接下来可以使用LayoutInflater对象的inflater的各种不同的方法来生产XML相应的对象。

在下面就是把该XML对象加入到响应的容器当中。可以是AlterDialog.Builder当中。调用该容器的setView方法即可。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics