码迷,mamicode.com
首页 > 移动开发 > 详细

关于Android LayoutInflater的解释

时间:2014-11-08 18:03:19      阅读:298      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   color   使用   sp   文件   div   on   

LayoutInflater的作用就是动态加载xml布局好的界面,类似于findViewById()来获取已经定义好的控件一样。不同点是LayoutInflater是用来找res/layout/下的xml布局文件,并且实例化;而findViewById()是找xml布局文件下的具体view控件(如Button、TextView等)。

具体的使用方法:

        //先获取系统服务
        LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        //然后即可获取xml布局文件
        View v = inflater.inflate(R.layout.customer_layout, null);
        //已经加载的布局就可以所以操作了
        TextView text = (TextView) v.findViewById(R.id.text1);

 

关于Android LayoutInflater的解释

标签:android   style   blog   color   使用   sp   文件   div   on   

原文地址:http://www.cnblogs.com/wytings/p/4083617.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!