- 浏览: 237083 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
江恂泽:
楼主 这家伙会把data 拆分开来 转换成day year形 ...
JsonUtil -
mdsp25xhm:
为何没有列表查询功能?
myBatis DAO封装
LayoutInflater作用是将layout的xml布局文件实例化为View类对象。
实现LayoutInflater的实例化共有3种方法,
(1).通过SystemService获得
LayoutInflater inflater = (LayoutInflater)context.getSystemServices(Context.LAYOUT_INFLATER_SERVICES);
View view = inflater.inflate(R.layout.main, null);
(2).从给定的context中获得
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.mian, null);
(3).
LayoutInflater inflater =getLayoutInflater();(在Activity中可以使用,实际上是View子类下window的一个函数)
View layout = inflater.inflate(R.layout.main, null);
其实,这三种方式本质是相同的,从源码中可以看出:
getLayoutInflater():
Activity的getLayoutInflater()方法是调用PhoneWindow的getLayoutInflater()方法,看一下该源代码:
publicPhoneWindow(Contextcontext) {
super(context);
mLayoutInflater= LayoutInflater.from(context);
}
可以看出它其实是调用LayoutInflater.from(context)。
LayoutInflater.from(context):
public static LayoutInflaterfrom(Context context) {
LayoutInflater LayoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(LayoutInflater== null){
thrownew AssertionError("LayoutInflaternot found.");
}
returnLayoutInflater;
}
可以看出它其实调用context.getSystemService()。
public View inflate(int Resourece,ViewGrouproot)
作用:填充一个新的视图层次结构从指定的XML资源文件中
reSource:View的layout的ID
root: 生成的层次结构的根视图
return 填充的层次结构的根视图。如果参数root提供了,那么root就是根视图;否则填充的XML文件的根就是根视图。
其余几个重载的inflate函数类似。
实现LayoutInflater的实例化共有3种方法,
(1).通过SystemService获得
LayoutInflater inflater = (LayoutInflater)context.getSystemServices(Context.LAYOUT_INFLATER_SERVICES);
View view = inflater.inflate(R.layout.main, null);
(2).从给定的context中获得
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.mian, null);
(3).
LayoutInflater inflater =getLayoutInflater();(在Activity中可以使用,实际上是View子类下window的一个函数)
View layout = inflater.inflate(R.layout.main, null);
其实,这三种方式本质是相同的,从源码中可以看出:
getLayoutInflater():
Activity的getLayoutInflater()方法是调用PhoneWindow的getLayoutInflater()方法,看一下该源代码:
publicPhoneWindow(Contextcontext) {
super(context);
mLayoutInflater= LayoutInflater.from(context);
}
可以看出它其实是调用LayoutInflater.from(context)。
LayoutInflater.from(context):
public static LayoutInflaterfrom(Context context) {
LayoutInflater LayoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(LayoutInflater== null){
thrownew AssertionError("LayoutInflaternot found.");
}
returnLayoutInflater;
}
可以看出它其实调用context.getSystemService()。
public View inflate(int Resourece,ViewGrouproot)
作用:填充一个新的视图层次结构从指定的XML资源文件中
reSource:View的layout的ID
root: 生成的层次结构的根视图
return 填充的层次结构的根视图。如果参数root提供了,那么root就是根视图;否则填充的XML文件的根就是根视图。
其余几个重载的inflate函数类似。
发表评论
-
IMF简介-2
2013-07-09 17:56 845InputManager 由UI控件(View,TextVie ... -
IMF简介-1
2013-07-09 17:51 771Input Method Framework 目录 ... -
输入法 总结-3
2013-07-08 15:02 813public class MainActivity exten ... -
输入法 总结-4
2013-07-04 17:29 896public class InputActivity exte ... -
输入法 总结-3
2013-07-04 17:28 824public class InputApplication e ... -
输入法 总结-2
2013-07-04 17:23 731openwnn_pref_ja.xml <?xml v ... -
输入法 总结-2
2013-07-04 17:21 13openwnn_pref_ja.xml <?xml v ... -
输入法 总结-1
2013-07-04 17:19 762<application android ... -
Android快捷键
2013-03-15 14:39 761Home键(小房子键) 在 ... -
如何通过wifi调试android程序
2013-02-27 15:48 705android手机居然可以通过wifi进行程序的调试,太好了, ... -
Please ensure that adb is correctly located at 'D:\android-sdk-windows\platform-
2013-02-27 14:27 1597adt 出现ADB server didn't ACK, fa ... -
Android AsyncTask
2013-02-19 09:35 1050AsyncTask是抽象类,子类 ... -
Android ViewPager 左右滑动2-1
2013-01-29 10:12 1397public class PagerActivity exte ... -
Android ViewPager 左右滑动-3
2013-01-29 10:10 1054<?xml version="1.0" ... -
Android ViewPager 左右滑动-2
2013-01-29 10:10 1393/*** * 选中效果 */ pu ... -
Android ViewPager 左右滑动-1
2013-01-29 10:09 1326Store extends ActivityGroup imp ... -
Android 下载
2013-01-27 00:59 861下载apk程序代码 protected File downLo ... -
Android SDCard操作-3
2013-01-26 18:31 839public static Intent getVid ... -
Android SDCard操作-2
2013-01-26 18:30 1023/** * 判断该应用在手机中的安装情况 ... -
Android SDCard操作-1
2013-01-26 18:27 986private static int INSTALLED = ...
相关推荐
本文主要介绍Android 中Inflate 方法的用法, 在开发Android应用过程中,可以在程序中应用 Inflate()方法加载新布局,希望能帮助有需要的朋友
最近一直想弄明白LayoutInflater对象的inflate方法的用法,今天做了实例。 <LinearLayout android:id=@+id/ll_item_Group android:layout_width=match_parent android:layout_height=200dp android:background=...
对于有一定Android开发经验的同学来说,一定使用过LayoutInflater.inflater()来加载布局文件,但并不一定去深究过它的原理,比如 1.LayoutInflater为什么可以加载layout文件? 2.加载layout文件之后,又是怎么变成供...
LayoutInflater在开发中使用频率很高,但是一直没有太知道LayoutInflater.from(context).inflate()的真正用法,今天就看看源码的流程。 首先来看from()的源码: /** * Obtains the LayoutInflater from the ...
本文实例讲述了Android开发中LayoutInflater用法。分享给大家供大家参考,具体如下: 在实际开发中LayoutInflater这个类还是非常有用的,它的作用类似于findViewById()。不同点是LayoutInflater是用来找res/layout/...
它的用法也无非就是LayoutInflater.inflate(resourceId, root, attachToRoot),第一个参数没什么好说的,但第二个和第三个参数结合起来会带来一定的迷惑性。之前有时候会发现界面布局上出了一些问题,查了很久之后...
由于本人刚刚学习Android 对于getViewById和getLayoutInflater().inflate()的方法该如何使用不知如何分别,这里就上网查下资料整理下,大家可以看下。 LayoutInflater 要明白这个问题首先要知道什么是...
1、对于一个没有被载入或者想要动态载入的界面,都需要使用LayoutInflater.inflate()来载入; 2、对于一个已经载入的界面,就可以使用Activiyt.findViewById()方法来获得其中的界面元素。 文档中的声明: public ...
大家好,今天给大家分享一下Android里的Context的一些用法. 这里大致可以分为两种:一是传递Context参数,二是调用全局的Context. 其实我们应用启动的时候会启动Application这个类,这个类是在AndroidManifest.xml...
介绍:分页加载和下拉刷新,几行代码完全搞定项目地址:https://github.com/tubeber/PageAndPullToRefresh运行效果:使用说明:本项目封装了分页请求和下拉刷新的全部过程,开发者只需要关注ListView子项...使用方法同2
文章目录引入效果图示例使用方法相关解释工具类封装最后奉上汪姑娘的Blog 引入 Android在需要类似于这样的弹窗会用到PopupWindow,所以,我为此封装了PopupWindow工具类,请往下看!!! 效果图 示例使用方法 ...
安卓Android单任务多线程任意断点下载【源码】,包括了一个可复用的文件下载服务类用于...使用inflate(int resource, ViewGroup root)方法生成新的View 4.调用当前页面中某个容器的addView,将新创建的View添加进来
Android有自带的对话框标题,但是不太美观,如果要给弹出的对话框设置一个自定义的标题,使用AlertDialog.Builder的setCustomTitle()方法。 运行效果如下,左边是点击第一个按钮,弹出Android系统自带的对话框(直接...
import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.chase.cn.money_of_my.R; /** * Created by Chase on 2017/2/6. */ public class Fragment_tab01 ...
<Button android:id="@+id/example_row_b_action_1" android:layout_width="0dp" android:layout_height="60dp" android:layout_gravity="center" android:layout_marginRight="10dp" android:layout_weight="1" ...
使用很方便,具体使用方法和API 请看后面的示例。 --- 左图为魅族APP上的Banner效果,右图是高仿效果。MZBannerView 有以下功能:1 . 仿魅族BannerView 效果。2 . 当普通Banner 使用3 . 当普通ViewPager 使用。...
项目地址:https://github.com/Arasthel/GoogleNavigationDrawerMenu效果图:如何使用方法1. 直接用java代码创建 1. 首先你需要创建个内容页的布局文件<?xml version="1.0" encoding="utf-8"?> xmlns:...
FlingCircleMenu 适用于Android的猛冲圈菜单 截屏 用法 protected void onCreate(Bundle savedInstanceState)... View item1 = LayoutInflater.from(this).inflate(R.layout.menu_item_layout,flingCircleMenuLayout,f