[Android学习笔记]LayoutInflater的使用

LayoutInflater用于动态载入布局,然后获取到布局中定义完成的控件引用

常在动态加载布局,和Adapter中用到

使用步骤:
1.通过LayoutInflater加载xml布局文件
2.从载入的View中获取引用

ex:
不需要具体例子,需要用到的时候,自然会想起只有它能满足需求

View view = LayoutInflater.from(context).inflate(R.layout.textview_btn,null); // 动态加载textview_btn.xml布局
Button btn = (Button)view.findViewById(R.id.btn);                                     // 获取textview_btn.xml布局文件中定义的控件的引用
TextView textView = (TextView)view.findViewById(R.id.textView);                //
LayoutInflater
人生就是一局不能Again的DOTA
原文地址:https://www.cnblogs.com/hellenism/p/3663883.html