码迷,mamicode.com
首页 > 移动开发 > 详细

android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams

时间:2015-05-13 18:52:17      阅读:472      评论:0      收藏:0      [点我收藏+]

标签:

LinearLayout layout = (LinearLayout) mInflater.inflate(
                    R.layout.cell_check_item, null);
            LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
                    UPDeviceInfo.getDeviceWidth(), LayoutParams.WRAP_CONTENT);
            rootLayout.addView(convertView, param);

我希望手动设置layout的宽度,结果就报错(虽然很小的几率报错)

java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams

 

解决方法:换成从原来的view中获取LayoutParams,而不是新建一个LayoutParams

LinearLayout.LayoutParams param = (android.widget.LinearLayout.LayoutParams) checkLayout
                    .getLayoutParams();
            param.width = UPDeviceInfo.getDeviceWidth();

看来,当一个View已经有了LayoutParams,最好不要添加一个新的LayoutParams。

android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams

标签:

原文地址:http://www.cnblogs.com/liupeipro/p/4501066.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!