Android开发点点滴滴——LayoutInflater及inflate方法
来源:互联网 发布:crm软件的使用方法 编辑:程序博客网 时间:2024/04/19 08:27
引言:
先看一段代码
public void OnCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main);这个是Activity创建时执行的方法,其中最后一句大家应该都见过,这个加载布局的最简单的方法,但是如果,你需要动态加载布局,那就需要使用其他办法。
那就是LayoutInfater的inflate方法。
一。获得 LayoutInflater 实例的三种方式
1.LayoutInflater inflater = getLayoutInflater(); //调用Activity的getLayoutInflater()
2.LayoutInflater localinflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
3. LayoutInflater inflater = LayoutInflater.from(context);
二。inflate方法
public View inflate(int Resourece,ViewGroup root)
作用:填充一个新的视图层次结构从指定的XML资源文件中
reSource:View的layout的ID
root: 生成的层次结构的根视图
return 填充的层次结构的根视图
如果参数root提供了,那么root就是根视图;否则填充的XML文件的根就是根视图。其余几个重载的inflate函数类似。
在View类中,也有inflate方法,相关的可以看下这篇文章
结束语:
这段代码和之前说的那最后一句是一个意思:
LayoutInflater inflate = LayoutInflater.from(this);View view = inflate.inflate(R.layout.main,null);setContentView(view);
- Android开发点点滴滴——LayoutInflater及inflate方法
- Android LayoutInflater及inflate方法
- Android layoutinflater inflate()方法
- Android:LayoutInflater的inflate方法
- Android LayoutInflater inflate方法效率
- (Android开发)LayoutInflater.inflate()参数详解
- Android编程之LayoutInflater的inflate方法
- [Android]LayoutInflater的inflate方法半详解
- android LayoutInflater和inflate()方法的用法
- android-----LayoutInflater的inflate方法详解
- android LayoutInflater和inflate()方法的用法
- Android - LayoutInflater和inflate方法的用法
- android LayoutInflater和inflate()方法的用法
- Android LayoutInflater.inflate()方法的参数用途
- Android LayoutInflater.inflate()方法参数详解
- LayoutInflater——inflate方法不同参数的区别
- LayoutInflater——inflate方法不同参数的区别
- LayoutInflater 中的 inflate() 方法
- 设计模式2 观察者模式
- 外在化应用参数的配置 spring <context:property-placeholder location="" />
- iOS 的 IAP 教程
- Android 桌面插件
- Quagga通信详解
- Android开发点点滴滴——LayoutInflater及inflate方法
- Storyboard全解析-第二部分
- Hibernate 对象的三种状态
- 随手笔记之VC++(六)
- 黑马程序员--05.类加载器--02【抽象类ClassLoader】【JVM加载类的过程】
- DEV控件的Gridview小技巧
- Hdu-2069_Coin Change
- 为什么打印出The window而不是My Object?
- 高性能网络编程3----TCP消息的接收