inflate用一个XML源填充view. LayoutInflater
android.view.LayoutInflater
This class is used to instantiate layout XML file into its corresponding View objects.
It is never be used directly --
use getLayoutInflater() or getSystemService(String) to retrieve a standard LayoutInflater instance
that is already hooked up to the current context and correctly configured for the device you are running on.
For example:
LayoutInflater inflater = (LayoutInflater)context.getSystemService
Context.LAYOUT_INFLATER_SERVICE);
常用方法有:
public View inflate (int resource, ViewGroup root)
Since: API Level 1
Inflate a new view hierarchy from the specified xml resource. Throws InflateException if there is an error.
Parameters
resource ID for an XML layout resource to load (e.g., R.layout.main_page)
root Optional view to be the parent of the generated hierarchy.
Returns
* The root View of the inflated hierarchy. If root was supplied, this is the root View; otherwise it is the root of the inflated XML file.
注意:如果root被提供的话,在把新生成的View连接到root后,返回root.否者返回的是新生成的View
public View inflate (int resource, ViewGroup root, boolean attachToRoot)
Since: API Level 1
Inflate a new view hierarchy from the specified xml resource. Throws InflateException if there is an error.
Parameters
resource ID for an XML layout resource to load (e.g., R.layout.main_page)
root Optional view to be the parent of the generated hierarchy (if attachToRoot is true), or else simply an object that provides a set of LayoutParams values for root of the returned hierarchy (if attachToRoot is false.)
attachToRoot Whether the inflated hierarchy should be attached to the root parameter? If false, root is only used to create the correct subclass of LayoutParams for the root view in the XML.
Returns
* The root View of the inflated hierarchy. If root was supplied and attachToRoot is true, this is root; otherwise it is the root of the inflated XML file.
注意:如果root被提供而且attachToRoot为TRUE的话,在把新生成的View连接到root,返回root.否者返回的是新生成的View。
如果root被提供但attachToRoot为FALSE的话,root只是把它的LayoutParams参数给新生成的View用,
不会把新生成的View连接到root。当然返回的是新生成的View。
版权声明:本文为博主原创文章,未经博主允许不得转载。
inflate用一个XML源填充view. LayoutInflater的更多相关文章
- [Android FrameWork 6.0源码学习] LayoutInflater 类分析
LayoutInflater是用来解析XML布局文件,然后生成对象的ViewTree的工具类.是这个工具类的存在,才能让我们写起Layout来那么省劲. 我们接下来进去刨析,看看里边的奥秘 //调用i ...
- Android数据填充器LayoutInflater
LayoutInflater类在应用程序中比较实用,可以叫布局填充器,也可以成为打气筒,意思就是将布局文件填充到自己想要的位置,LayoutInflater是用来找res/layout/下的xml布局 ...
- Android通过xml生成创建View的过程解析
Android的布局方式有两种,一种是通过xml布局,一种是通过java代码布局,两种布局方式各有各的好处,当然也可以相互混合使用.很多人都习惯用xml布局,那xml布局是如何转换成view的呢?本文 ...
- android开发中一个activity如何调用另一个xml中的控件
有时候,我们需要在一个activity中使用另一个activity中的控件,这时候就不能直接findViewById,不然会报错指向空对象,这时就需要像下面这样做. LayoutInflater fa ...
- at android.view.LayoutInflater.createViewFromTag的错误原因
创建对话框时出现下面的错误: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean ...
- php动态生成一个xml文件供swf调用
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdo ...
- 写一个xml文件到磁盘的方法
/** * 往磁盘上写一个xml文件 * * <?xml version="1.0" encoding="UTF-8" standalone=" ...
- 一个lucene源码分析的博客
ITpub上的一个lucene源码分析的博客,写的比较全面:http://blog.itpub.net/28624388/cid-93356-list-1/
- 判断本地系统目录下是否存在XML文件,如果不存在就创建一个XMl文件,若存在就在里面执行添加数据
这是我为项目中写的一个测试的例子, 假如,您需要这样一个xml文件, <?xml version="1.0" encoding="utf-8"?> ...
随机推荐
- 如何在vue项目中使用md5.js及base64.js
一.在项目根目录下安装 npm install --save js-base64 npm install --save js-md5 二.在项目文件中引入 import md5 from 'js-md ...
- light oj 1427(ac自动机)
#include <bits/stdc++.h> using namespace std; *; ; map<string,int>Map; struct Trie { int ...
- java -cp ../../DESUtil/ Hello,用-cp指定classpath
运行hello.class 文件 怎么用 java +路径 就是不在class目录下运行 怎么做??? 我想要的是 java 直接去运行某个路径下的class文件 不想到它的目录那里再java hel ...
- 微信小程序 原生框架 (分享方法封装)
封装的分享方法 function share(o,isDebug = false ) { //路径 let url = o.url || getCurrentPages()[getCurrentPag ...
- Linux安装Desktop 和 vncserver
sudo su - #使用 root 账户 yum grouplist #查看所有可用的group yum groupinstall GNOME Desktop #安装 GNOME 桌面 yum -y ...
- NOIP模拟17.9.22
NOIP模拟17.9.22 前进![问题描述]数轴的原点上有一只青蛙.青蛙要跳到数轴上≥
- R语言可视化--qplot函数
ggplot绘图系统 使用动词名词形容词构造句子的过程,将数据映射到美学属性上的过程,由层组成 绘图函数 qplot() :参数包括美学属性.几何体.面.统计.坐标系.主题这些层次. ggplot() ...
- Nacos Committers 团队首亮相,发布 0.9.0 版本
223 天,发布 14 个版本,19 位 Committers,39 位 Contributors. 在宣布开源后的第 223 天,Nacos 发布了其第14个版本 - 0.9.0,该版本提升了 Na ...
- 【python之路16】作业
#!usr/bin/env python # -*- coding:utf-8 -*- # 数据库中原有 old_dict = { "#1": {'hostname': 'c1', ...
- LUOGU P2587 [ZJOI2008]泡泡堂
传送门 解题思路 刚开始先写了个田忌赛马的贪心,就是要是打不过就拿最弱的送死,30分...后来瞄了眼题解,发现这样是错的,比如说这样的数据 : 3 3 2 3 1 如果用田忌赛马的话,让2-3 3-1 ...