首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

LayoutParams跟LayoutInflater理解

2012-06-27 
LayoutParams和LayoutInflater理解LayoutParams继承于Android.view.ViewGroup.LayoutParamsLayoutParams封

LayoutParams和LayoutInflater理解
LayoutParams继承于Android.view.ViewGroup.LayoutParams
LayoutParams封装了Layout的高,宽等信息,假设一个区域由一个Layout占领,如果将一个View添加到Layout中,需要告诉Layout用户期望的布局方式,即将一个认可的LayoutParams传递进去。
LayoutParams描述的宽高的值可以设置为下边3个值中的任何一种:
一个确定的值;
FILL_PARENT,即View希望和父容器一样大;
WRAP_CONTENT,指当前的View的大小只需要包裹住View里面的内容即可。

LayoutInflater inflate = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);//LayoutInflater需要通过getSystemService方法来获得,而不能直接实例化RelativeLayout layoutLeft = (RelativeLayout) inflate.inflate(R.layout.left, null);//调用inflate方法将left.xml进行解析,并生成一个RelativeLayout布局

热点排行