ListView的LayoutParams设置
2015-06-11 11:50
501 查看
// Temp is the root view that was found in the xml final View temp = createViewFromTag(root, name, attrs, false); ViewGroup.LayoutParams params = null; if (root != null) { if (DEBUG) { System.out.println("Creating params from root: " + root); } // Create layout params that match root, if supplied params = root.generateLayoutParams(attrs); if (!attachToRoot) { // Set the layout params for temp if we are not // attaching. (If we are, we use addView, below) temp.setLayoutParams(params); } }
从上面可以看到,如果在inflate xml文件时,如果没有指定parent的时候,layout_width是不会生效的。
mInflater.inflate(R.layout.apps_listview_item, parent, false);
<com.helen.launcher4.TestLinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="160dp" android:orientation="horizontal" android:paddingTop="5dp" android:paddingBottom="5dp">
上面的160dp,如果没有指定parent,是不会生效。
当然这里的parent其实就只有一个目的,使layoutparam生效,其他毫无目的,所以随便指定一个view即可,这里android设计的不太好。
如果没有指定parent,layoutparam默认值是什么呢?
Listview是设计成一个可以上下滚动的viewgroup,所以width是占ListView所有的宽度,即MeasureSpec.EXACTLY
height呢?高度是MeasureSpec.UNSPECIFIED, size = 0.
也就是说,高度是随意定的。这会带来一个问题,当子节点使用match_parent的时候,子节点并不知道parent有多少高度,所以子节点的MeasureSpec会是UNSPECIFIED。
GridView在处理UNSPECIFIED的时候,很奇怪,并不是wrap_content。到底怎么处理,下面的文章再来细述。
相关文章推荐
- 用ext_skel,实现一个PHP扩展,添加到PHP并调用
- php中smarty变量修饰用法实例分析
- php知识点
- php简单smarty入门程序实例
- FTP 实现跨服务器文件上传下载
- php类的静态单列模式的实现方法
- PhpStorm下Laravel代码智能提示
- Yii学习笔记之五(核心验证器 api 翻译)
- 关于PHP+Mysql1045 Access denied for user错误解决办法――你可能想不到的
- Sublime Text [Decode error - output not utf-8]
- php调试函数xdebug_debug_zval和debug_backtrace(需要安装xdebug)x
- php判断一个值是否在一个数组中,区分大小写-也可以判断是否在键中
- IIS6.0搭建FTP服务器,以及建立多用户FTP
- ContentProvider
- setprecision(int n)等格式函数用法
- setprecision(int n)等格式函数用法 分类: POJ 2015-06-11 10:56 17人阅读 评论(0) 收藏
- PHP设计模式——职责链模式
- vsftp
- laravel5.0升级到5.1
- PHP设计模式——访问者模式