Android之Inflate()方法用途
转自:http://blog.csdn.net/andypan1314/article/details/6715928
Inflate()作用就是将xml定义的一个布局找出来,但仅仅是找出来而且隐藏的,没有找到的同时并显示功能。最近做的一个项目就是这一点让我迷茫了好几天。
android上还有一个与Inflate()类似功能的方法叫findViewById(),二者有时均可使用,但也有区别
区别在于:
如果你的Activity里用到别的layout,比如对话框layout,你还要设置这个layout上的其他组件的内容,你就必须用inflate()方法先将对话框的layout找出来,然后再用findViewById()找到它上面的其它组件。例如:
- View view1=View.inflate(this,R.layout.dialog_layout,null);
- TextViewdialogTV=(TextView)view1.findViewById(R.id.dialog_tv);
- dialogTV.setText("abcd");
注:R.id.dialog_tv是在对话框layout上的组件,而这时若直接用this.findViewById(R.id.dialog_tv)肯定会报错。
- View viewStub = ((ViewStub) findViewById(R.id.stubView)).inflate();
Inflate()或可理解为“隐性膨胀”,隐性摆放在view里,inflate()前只是获得控件,但没有大小没有在View里占据空间,inflate()后有一定大小,只是出于隐藏状态
Android之Inflate()方法用途的更多相关文章
- Android layoutInflate.inflate 方法具体解释,removeView()错误解决
错误: The specified child already has a parent. You must call removeView(). 解答: 这个错误非常直白,就是你viewGroup. ...
- android LayoutInflater和inflate()方法的用法(转载)
原文出处:http://www.cnblogs.com/top5/archive/2012/05/04/2482328.html 在实际开发中LayoutInflater这个类还是非常有用的,它的作用 ...
- Android编程之LayoutInflater的inflate方法实例
假设你不关心其内部实现,仅仅看怎样使用的话,直接看这篇就可以. 接上篇,接下来,就用最最简单的样例来说明一下: 用两个布局文件main 和 test: 当中,main.xml文件为: <?xml ...
- Android编程之LayoutInflater的inflate方法详解
LayoutInflater的inflate方法,在fragment的onCreateView方法中经常用到: public View onCreateView(LayoutInflater infl ...
- 【Android 界面效果43】Android LayoutInflater的inflate方法中attachToRoot的作用
我们在ListView的Adapter的getView方法里面经常会调用两个参数的inflate方法, mInflater.inflate(R.layout.adv_viewpager, null); ...
- Android编程之LayoutInflater的inflate方法具体解释
LayoutInflater的inflate方法,在fragment的onCreateView方法中经经常使用到: public View onCreateView(LayoutInflater in ...
- View.inflate和LayoutInflater的inflate方法区别
平时ListView加载item中,adapter的getView方法中,我们经常用到: LayoutInflater.from(mContext).inflate(R.layout.it ,pare ...
- [转]JS调用Android里面的方法,Android调用JS里面的方法
FROM : http://blog.csdn.net/hj563308597/article/details/45197709 Android WebView 在公司Android的开发过程中遇到一 ...
- Android之Inflate()
Inflate()作用就是将xml定义的一个布局找出来,但仅仅是找出来而且隐藏的,没有找到的同时并显示功能.最近做的一个项目就是这一点让我迷茫了好几天. Android上还有一个与Inflate( ...
随机推荐
- set JAVA_HOME in RHEL/CentOS
3.3. Install OpenJDK on Red Hat Enterprise Linux Introduction OpenJDK is one of many Java Developmen ...
- link
public IEnumerable InsuranceSearch(InsuranceSC sc, out int TotalCount) { var data = from q in Insura ...
- assembly打包。
--排除 <?xml version="1.0" encoding="UTF-8"?><assembly xmlns="htt ...
- EntityFramework+WCF
首先需要在服务对象实例上面添加数据契约[DataContract]和 [DataMember],当然直接在类中修改也可以,但是对于tt模板来说一旦保存以后数据就会重新生成, 所以得在tt模板中修改 ...
- SQLServer日志无法收缩原因分析及解决
SQL Server中的事务日志无疑是SQL Server中最重要的部分之一.因为SQL SERVER利用事务日志来确保持久性(Durability)和事务回滚(Rollback).从而还部分确保了事 ...
- nullcon HackIM 2016 -- Programming Question 1
So you reached Delhi and now the noise in your head is not allowing you to think rationally. The Nos ...
- Codeforces Round #243
CF 243 DIV1 & DIV2 DIV2的A和B都太水,直接暴力搞就可以的. DIV2A /* ******************************************** ...
- [转]深入分析 Java 中的中文编码问题
收益匪浅,所以转发至此 原文链接: http://www.ibm.com/developerworks/cn/java/j-lo-chinesecoding/ 深入分析 Java 中的中文编码问题 编 ...
- Boo who
function boo(bool) { // What is the new fad diet for ghost developers? The Boolean. //return bool; r ...
- Scrum会议(Beta版本)
组名:天天向上 组长:王森 组员:张政.张金生.林莉.胡丽娜 代码地址:HTTPS:https://git.coding.net/jx8zjs/llk.git SSH:git@git.coding.n ...