原因:代码设置宽度,如果使用ViewGroup.LayoutParams 就会跑不起来,换成RelativeLayout.LayoutParams就可以了。
错误的设置方式
ViewGroup.LayoutParams lp;
lp = ll_footer.getLayoutParams();
lp.width = (int) footerWith;
lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
ll_footer.setLayoutParams(lp);
正确的设置方式一
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(274, RelativeLayout.LayoutParams.FILL_PARENT);
经测试方式一在模拟器上没问题,在真机上总报
android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
的 bug
后改为
AbsListView.LayoutParams layoutParams
= new AbsListView.LayoutParams(levelWith, (int) height);
问题解决了。
参考连接:
http://www.cnblogs.com/dyllove98/archive/2013/07/11/3184844.html