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。

时间: 2024-07-30 13:48:07

android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams的相关文章

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

错误日志1: 06-13 10:55:50.410: E/KVLog(1129): Error info:java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams06-13 10:55:50.423: E/KVLog(1129): Cause Result:java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams06-13 10:

java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.L(转)

09-09 10:19:59.979: E/AndroidRuntime(2767): FATAL EXCEPTION: main09-09 10:19:59.979: E/AndroidRuntime(2767): java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams09-09 10:19:59.97

android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams

java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widg 时间 2013-09-23 22:36:41  傲慢的上校的专栏原文  http://blog.csdn.net/lilu_leo/article/details/11952717 有时候需要在在代码中设置LayoutParams,自己为一个FrameLayout设置LayoutParams的时候

Android View体系(十一)自定义ViewGroup

相关文章 Android View体系(一)视图坐标系 Android View体系(二)实现View滑动的六种方法 Android View体系(三)属性动画 Android View体系(四)从源码解析Scroller Android View体系(五)从源码解析View的事件分发机制 Android View体系(六)从源码解析Activity的构成 Android View体系(七)从源码解析View的measure流程 Android View体系(八)从源码解析View的layout

Android View的生命周期详解

View生命周期相关方法: onFinishInflate() 当View中所有的子控件均被映射成xml后触发 onMeasure( int ,  int ) 确定所有子元素的大小 onLayout( boolean ,  int ,  int ,  int ,  int ) 当View分配所有的子元素的大小和位置时触发 onSizeChanged( int ,  int ,  int ,  int ) 当view的大小发生变化时触发 onDraw(Canvas) view渲染内容的细节 onK

深入懂得android view 生命周期

作为自定义 view 的基础,如果不了解android  view 的生命周期 , 那么你将会在后期的维护中发现这样那样的问题 ....... 做过一段时间android 开发的同学都知道,一般 onXXX 函数都是系统的回调函数.而这篇 blog 也是基于这个思想(或许有点笨)......   首先来看三分  创建view 的 日志信息 (自定义View 配置到xml文件中): android:visibility=gone 03-25 19:56:55.934: D/yyyyy(11493)

Android View measure (五) 支持margin属性,从一个异常说起

先来看下代码 一.查看夏目 1. 自定义控件 public class CustomViewGroup extends ViewGroup { ...... @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); // 遍历所有子视图,进行measure操作 for (int i =

深入理解android view 生命周期

作为自定义 view 的基础,如果不了解Android  view 的生命周期 , 那么你将会在后期的维护中发现这样那样的问题 ....... 做过一段时间android 开发的同学都知道,一般 onXXX 函数都是系统的回调函数.而这篇 blog 也是基于这个思想(或许有点笨)...... 首先来看三分  创建view 的 日志信息 (自定义View 配置到xml文件中): android:visibility=gone [html] view plain copy 03-25 19:56:5

Android View体系(八)从源码解析View的layout和draw流程

相关文章 Android View体系(一)视图坐标系 Android View体系(二)实现View滑动的六种方法 Android View体系(三)属性动画 Android View体系(四)从源码解析Scroller Android View体系(五)从源码解析View的事件分发机制 Android View体系(六)从源码解析Activity的构成 Android View体系(七)从源码解析View的measure流程 前言 上一篇文章我们讲了View的measure的流程,接下来我们