首页 > 代码库 > android setLayoutParams 问题,出错

android setLayoutParams 问题,出错

1             LinearLayout layt = (LinearLayout) rootView.findViewById(R.id.llt_2);2             FrameLayout.LayoutParams layoutParams=new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);3             layoutParams.gravity=Gravity.CENTER;            4             layt.setLayoutParams(layoutParams);

技术分享

关键:

主是要是在定义layoutParams的时候要用view的父容器类去声明,而它本身,

new FrameLayout.LayoutParams参数也一样要用父,

可参考:http://blog.csdn.net/greenappple/article/details/7631430

android setLayoutParams 问题,出错