关于Android LayoutInflater的解释

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);

 

posted @ 2014-11-08 16:43  RexWei  阅读(163)  评论(0编辑  收藏  举报