inflate中的参数
来源:互联网 发布:javascript 书 编辑:程序博客网 时间:2024/05/17 23:35
public View inflate (int resource, ViewGroup root, boolean attachToRoot)
resource : 需要加载的Layout的xml资源
root : 表示获得容器视图对象后,要将获得的该对象添加到哪个容器视图对象中, 如果不想将要获得的对象添加到任何其他容器中 则为NULL
attachToRoot : 是否和root关联
注意: 如果root被提供而且attachToRoot为TRUE的话,在把新生成的View连接到root,返回root.否者返回的是新生成的View.
如果root被提供但attachToRoot为FALSE的话,root只是把它的LayoutParams参数给新生成的View用,不会把新生成的View连接到root . 当然返回的是新生成的View
对于第三个参数请看如下实验:
main.xml:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <FrameLayout android:id="@+id/ffff" android:layout_width="match_parent" android:layout_height="wrap_content"></FrameLayout> </LinearLayout>
ffff.xml:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <CheckBox android:id="@+id/checkBox1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="CheckBox" /> </LinearLayout>activity 中的部分代码:
setContentView(R.layout.main);ViewGroup v = (ViewGroup) findViewById(R.id.ffff);View vv = LayoutInflater.from(this).inflate(R.layout.ffff, v);效果如下:
视图层次结构如下:
如activity代码为:
View vv = LayoutInflater.from(this).inflate(R.layout.ffff, v, false);效果如下:
层次结构如下:
如果activity中的代码如下:
ViewGroup v = (ViewGroup) findViewById(R.id.ffff);View vv = LayoutInflater.from(this).inflate(R.layout.ffff, v, false);v.addView(vv);
效果如下:
0 0
- inflate中的参数
- LayoutInflater中的inflate参数的定义
- LayoutInflater inflate参数详解
- inflate第三个参数
- inflate()参数的问题
- inflate参数含义
- Inflate三个参数
- LayoutInflater inflate参数详解
- inflate参数释义
- inflate方法参数总结
- LayoutInflater.inflate参数详解
- 【Android】【Inflate】inflate方法的三个参数
- LayoutInflater 中的 inflate() 方法
- android 中的inflate
- LayoutInflater中的inflate方法
- Android中的inflate作用
- Android中的inflate用法
- android-中的inflate
- 手动赋值操作结构体
- python初学者使用wingIDE
- oc6
- Solving “Dynamic Web Module 3.0 requires Java 1.6 or newer” in Maven Projects
- 三级联动的省市县下拉菜单
- inflate中的参数
- Linux20-shell编程基础、数值计算、字符串处理
- C++代码实现快速排序
- Runloop学习总结
- Java HashMap源码简析
- C语言读取文本文档里面的字符and 和只读一行;
- 我电脑上python相关软件
- UVa:10494 - If We Were a Child Again
- c++ part3