Android学习 6->浅谈界面显示与LayoutInflater
来源:互联网 发布:2016年4月1日非农数据 编辑:程序博客网 时间:2024/06/05 20:31
LayoutInflater 是用于加载布局的,在Android中是“扩展”的意思,作用类似于findViewById(),不同的是LayoutInflater是用来获得布局文件对象的,而findViewById()是用来获得具体控件的。加载布局的任务通常都是在Activity中调用setContentView()方法来完成的。而setContentView()方法的内部也是使用LayoutInflater来加载布局的。
LayoutInflater的基本用法:
第一步:
LayoutInflater mInflater = LayoutInflater.from(context);
第二步:
ViewGroup parent; View v = mInflater.inflate(R.layout.item_simpleadapter_view, parent,true); View v = mInflater.inflate(R.layout.item_simpleadapter_view, parent,false); View v = mInflater.inflate(R.layout.item_simpleadapter_view, null);
注意: public View inflate(int resourceId, ViewGroup root, boolean attachToRoot)
如果设置了ViewGroup root参数,且attachToRoot设置为false的话,则会从root中得到由layout_width和layout_height组成的LayoutParams,就会对我们加载的视图View设置该LayoutParams。
如果设置了ViewGroup root参数,且attachToRoot设置为true的话,则将我们加载的视图做为子视图添加到root视图中。
如果我们ViewGroup root设置为空的话,就直接返回我们创建的视图;
Android界面显示的原理
任何一个Activity中显示的界面其实主要都由两部分组成: 标题栏和内容布局。
标题栏就是在很多界面顶部显示的那部分内容,可以在代码中控制让它是否显示。
内容布局就是一个FrameLayout,这个布局的id叫作content,我们调用setContentView()方法时所传入的布局其实就是放到这个FrameLayout中的,这也是为什么这个方法名叫作setContentView(),而不是叫setView()。
下图为一个Activity窗口组成结构:
- Android学习 6->浅谈界面显示与LayoutInflater
- Android学习之LayoutInflater动态载入activity界面
- Android LayoutInflater学习
- Android-LayoutInflater学习
- android LayoutInflater学习
- Android学习笔记 LayoutInflater
- Android-学习-layoutInflater学习心得
- android LayoutInflater.inflate()学习
- Android View与LayoutInflater
- 浅谈 LayoutInflater
- Android布局学习之LayoutInflater
- Android学习---解决Android Graphical Layout 界面效果不显示
- 【Android 界面效果23】LayoutInflater作用及使用
- Android 界面全屏显示
- android 界面显示ProgressLayout
- android 入门学习笔记 LayoutInflater的使用
- 【Android进阶学习】LayoutInflater的应用
- Android学习之LayoutInflater类的使用
- jquery鼠获取标滚轮次数(1)
- Java数据库连接池dbcp的用法
- 父亲节就快到了,为老爸接力一下好吗?
- HDU-1049-Climbing Worm(C++ && 编程初学者的题......)
- JSON 字符串 与 java 对象的转换
- Android学习 6->浅谈界面显示与LayoutInflater
- Build HSS and Config Phpmyadmin
- Spark入门——5 SparkSQL
- 九度OJ-题目1509:树中两个结点的最低公共祖先
- 关于C++多重继承的时候虚函数覆盖的问题
- 我为什么从 Python 转向 Go?
- OPENCV笔记(一)图像显示
- 程序员的量化交易(34)--QuantConnect_Lean如何定义Indicator指标2
- 一个架构师谈什么是架构以及怎么成为一个架构师