LinearLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
2015-05-14 11:08
357 查看
不同Layout,对应不同Layoutparameter,那么被嵌套的布局或者view,要尊用父布局的Layoutparameter类。
因为你的这个LinearLayout是放在一个ListView中(ListView是AbsListView的子类),所以LinearLayout.setLayoutParameters()中应该放AbsListView.LayoutParameter这个类的对象。
相关Bug:
1)java.lang.ClassCastException: android.widget.LinearLayoutLayoutParamscannotbecasttoandroid.widget.RelativeLayoutLayoutParams cannot be cast to android.widget.RelativeLayoutLayoutParams
:这段话提示我们不能将LinearLayoutParams强制转换成RelativeLayoutLayoutParams强制转换成RelativeLayoutLayoutParams
3
2):java.lang.ClassCastException: android.widget.LinearLayoutLayoutParamscannotbecasttoandroid.widget.AbsListViewLayoutParams cannot be cast to android.widget.AbsListViewLayoutParams
在DDMS里面也没有具体定位哪里错了,逐步调试在return那里出错了,求解?
——解决方案——————–
LinearLayout.LayoutParams _llp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.MATCH_PARENT);
这句代码导致的错误哦
——解决方案——————–
因为你的这个LinearLayout是放在一个ListView中(ListView是AbsListView的子类),所以LinearLayout.setLayoutParameters()中应该放AbsListView.LayoutParameter这个类的对象。
比如我的ListView一项配置如下:
因为你的这个LinearLayout是放在一个ListView中(ListView是AbsListView的子类),所以LinearLayout.setLayoutParameters()中应该放AbsListView.LayoutParameter这个类的对象。
相关Bug:
1)java.lang.ClassCastException: android.widget.LinearLayoutLayoutParamscannotbecasttoandroid.widget.RelativeLayoutLayoutParams cannot be cast to android.widget.RelativeLayoutLayoutParams
:这段话提示我们不能将LinearLayoutParams强制转换成RelativeLayoutLayoutParams强制转换成RelativeLayoutLayoutParams
3
2):java.lang.ClassCastException: android.widget.LinearLayoutLayoutParamscannotbecasttoandroid.widget.AbsListViewLayoutParams cannot be cast to android.widget.AbsListViewLayoutParams
在DDMS里面也没有具体定位哪里错了,逐步调试在return那里出错了,求解?
——解决方案——————–
LinearLayout.LayoutParams _llp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.MATCH_PARENT);
这句代码导致的错误哦
——解决方案——————–
因为你的这个LinearLayout是放在一个ListView中(ListView是AbsListView的子类),所以LinearLayout.setLayoutParameters()中应该放AbsListView.LayoutParameter这个类的对象。
比如我的ListView一项配置如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:weightSum="2" android:id="@+id/ll_item_camera" > <RelativeLayout android:id="@+id/rl_camera_left" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent"> <ImageView android:id="@+id/iv_camera_left_check" android:layout_width="30dp" android:layout_height="30dp" android:scaleType="fitXY" android:src="@drawable/checked" android:layout_alignParentRight="true" android:layout_marginTop="5dp" android:layout_marginRight="5dp"/> </RelativeLayout> <RelativeLayout android:id="@+id/rl_camera_right" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:layout_marginLeft="10dp"> <ImageView android:id="@+id/iv_camera_right_check" android:layout_width="30dp" android:layout_height="30dp" android:scaleType="fitXY" android:src="@drawable/checked" android:layout_alignParentRight="true" android:layout_marginTop="5dp" android:layout_marginRight="5dp"/> </RelativeLayout> </LinearLayout>
AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, this.cameraHeight); mViewHolder.ll_item_camera.setLayoutParams(layoutParams);
相关文章推荐
- android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutPara
- ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.AbsLis
- 解决 android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- 报错:ViewPager$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- 解决 android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- 报错:ViewPager$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- ListView的一个典型crash cannot be cast to android.widget.AbsListView$LayoutParams
- android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
- android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutPara
- java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.wi
- :java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.wi
- java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.wid