android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
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。