动态添加视图时,如何确定LayoutParams的类型
来源:互联网 发布:计算机编程好学么 编辑:程序博客网 时间:2024/05/29 04:55
在使用addView(View child, LayoutParams params)动态增加view视图时,其中第二个参数为LayoutParams params。该LayoutParams可定义为不同的类型,包括LinearLayout,RelativeLayout,FrameLayout等,到底采用哪种类型的布局方式呢?这要看谁调用了addView这个方法,举个例子:
LinearLayout ll_layout = (LinearLayout)findViewById(R.id.ll_layout);
ll_layout.addView(View child, LayoutParams params);
那么上面这个params定义为何种类型的LayoutParams呢?
因为ll_layout是LinearLayout 类型,因此params应该如下创建:
LinearLayout.LayoutParams params = new
LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT); params.setMargins(100, 50,
80, 100);
上面相当于child这个子类在xml的布局为如下定义:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/ll_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:descendantFocusability="blocksDescendants" android:orientation="horizontal" android:background="#ffffff"> <TextView android:id="@+id/text_view" android:layout_width="wrap_content" android:layout_height="50dp" android:layout_centerVertical="true" android:gravity="left|center_vertical" android:textColor="#000" /><!--该Button为上面的child子类--> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="100dp" android:layout_marginLeft="100dp" android:layout_marginRight="80dp" android:layout_marginTop="50dp" /></LinearLayout>
0 0
- 动态添加视图时,如何确定LayoutParams的类型
- 动态添加布局-LayoutParams
- C++如何确定常量的类型
- 视图链中如何确定根视图
- 8.SpringMVC_如何确定目标方法POJO类型参数/视图解析流程分析/
- Zabbix --> 客户端安装以及如何添加数据库的动态监控视图
- 数据库创建视图时如何指定自定义列的类型
- Android动态添加视图
- 转载的 如何在运行时确定对象类型(RTTI)
- 如何确定各种类型的取值范围?
- Android 如何动态设置View参数,LayoutParams.addRules详解,TypedValue.applyDimension的使用
- 动态链接如何确定是调用的哪一个函数
- LayoutInflater 和LayoutParams一起实现动态添加控件
- 如何在运行时确定对象类型(RTTI)
- 如何在运行时确定对象类型(RTTI)
- 如何在运行时确定对象类型(RTTI)
- 如何在运行时确定对象类型(RTTI)
- 转:如何在运行时确定对象类型(RTTI)
- Mac 下安装Ruby环境
- 破解TexturePacker加密资源
- C++头文件
- 微软100题(17)字符串中只出现一次的字母
- 【oracle唯一主键SYS_GUID()】
- 动态添加视图时,如何确定LayoutParams的类型
- Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"
- 【深入Java虚拟机】之六:Java语法糖
- Unity 优化
- SOMIC E95振动设置
- Cocos2d-js研究:发布H5成果
- 一步一步教你用PHP+MySql搭建网站 No.4 文章编辑、图片上传
- 【oracle服务】
- OPENGL的坐标系统变换