首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

XxxInflater的应用

2012-08-29 
XxxInflater的使用android 提供了一个工具 能够把int 的 *.xml 文件转化为 View 这就是XxxInflater 主要有

XxxInflater的使用
android 提供了一个工具 能够把int 的 *.xml 文件转化为 View 这就是XxxInflater 主要有2种:
* LayoutInflater
* MenuInflater
通常使用:

MenuInflater mInflater = getMenuInflater();
LayoutInflater lInflater = getLayoutInflater();


上述二者仅在 Activity 中才有效!

MenuInflater具体使用方法
比如现在在res目录下创建menu文件夹有一个关于menu的描述文件 menu_item.xml 如下:



现在把它转化为 View.



LayoutInflater 和 MenuInflater 的使用基本类似 也是根据int 的 *.xml 文件得到 View 所不同的就是 嵌套原因 所以多了一个参数-ViewGroup 用来表示 父View 比如:在 LinearLayout layout 里面有一个 TextView 且其用tv.xml 描述 那么应该如下使用

LayoutInflater inflater = getLayoutInflater();
inflater.inflate(R.layout.tv,layout);

热点排行