`
- 浏览:
252066 次
- 性别:
- 来自:
上海
-
原文:
http://daydayup1989.iteye.com/blog/824735
通俗的说,inflate就相当于将一个xml中定义的布局找出来.
因为在一个Activity里如果直接用findViewById()的话,对应的是setConentView()的那个layout里的组件.
因此如果你的Activity里如果用到别的layout,比如对话框上的layout,你还要设置对话框上的layout里的组件(像图片 ImageView,文字TextView)上的内容,你就必须用inflate()先将对话框上的layout找出来,然后再用这个layout对象去找到它上面的组件,如:
View view = View.inflate(this, R.layout.dialog_layout, null);
TextView dialogTV = (TextView) view.findViewById(R.id.dialog_tv);
dialogTV.setText("abcd");
如果组件R.id.dialog_tv是对话框上的组件,而你直接用this.findViewById(R.id.dialog_tv),那么返回值将是null
三种方式可以生成LayoutInflater :
LayoutInflater inflater = LayoutInflater.from(this);
LayoutInflater inflater = getLayoutInflater();
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
然后调用inflate方法将xml布局文件转成View
public View inflate (int resource, ViewGroup root, boolean attachToRoot)
在View类中,也有inflate方法
public static View inflate (Context context, int resource, ViewGroup root)
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
这个demo主要实现了inflate的使用,希望可以帮助需要的同学.
博客《ListView滑动删除实现之一——merge标签与LayoutInflater.inflate()》对应源码,博客地址:http://blog.csdn.net/harvic880925/article/details/45155965
本文主要介绍Android 中Inflate 方法的用法, 在开发Android应用过程中,可以在程序中应用 Inflate()方法加载新布局,希望能帮助有需要的朋友
Android LayoutInflater.inflate()详解 深入理解LayoutInflater.inflate() 由于我们很容易习惯公式化的预置代码,有时我们会忽略很优雅的细节。LayoutInflater以及它在Fragment的onCreateView()中填充View的方式...
android inflate demo,方便新手使用,下载导入android studio就可直接运行,简单明了的展现inflate不同参数的区别
Android 中LayoutInflater.inflate()方法的介绍 最近一直想弄明白LayoutInflater对象的inflate方法的用法,今天做了实例。 <LinearLayout android:id=@+id/ll_item_Group android:layout_width=match_parent ...
主要介绍了Android LayoutInflater.inflate源码分析的相关资料,需要的朋友可以参考下
帮助你更好的理解LayoutInflate中的inflate方法,以后想怎么用怎么用
Android getViewById和getLayoutInflater().inflate()的详解及比较 由于本人刚刚学习Android 对于getViewById和getLayoutInflater().inflate()的方法该如何使用不知如何分别,这里就上网查下资料整理下,大家可以...
View contentView = inflater.inflate(R.layout.layout_pop, null); NewFloatMainWindow.getFloatMainWindow(MainActivity.this, NewFloatMainWindow.LOCATION_LEFT, contentView); 3.实现悬浮窗如此简单 readme-...
本文实例讲述了Android开发中setContentView和inflate的区别。分享给大家供大家参考,具体如下: 一般用LayoutInflater做一件事:inflate inflate这个方法总共有四种形式(见下面),目的都是把xml表述的layout转化...
View v = inflater.inflate(R.layout.main, null); addView(v); mArgButton = (Button)v.findViewById(R.id.arg_button); mGlobleButton = (Button)v.findViewById(R.id.glo_button); mExitButton = ...
Inflate有三个参数,我在初学Android的时候这么理解的: (1)对于Inflate的三个参数(int resource, ViewGroup root, boolean attachToRoot); (2)如果inflate(layoutId, null )则layoutId的最外层的控件的宽高是...
Android 实现各个方向的气泡弹窗,可控制气泡尖角偏移量。 截图 依赖 dependencies { compile 'com.yuyh.bubble:library:1.0.0' } 使用 默认弹窗BubblePopupWindow leftTopWindow = new BubblePopupWindow...
import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.webkit.WebView; ...
LayoutInflater.from(context).inflate()方法的调研
android自定义view之组合控件、重写控件