android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams
来源:互联网 发布:前端ajax模拟数据 编辑:程序博客网 时间:2024/05/17 08:19
FrameLayout的父控件是一个LinearLayout控件,问题出在,LinearLayout为子控件分配空间的时候,获取FrameLayout的LayoutParams的必须为LinearLayout.LayoutParams,而非FrameLayout.LayoutParams。
简单的举个栗子说明一下:最外层有ReLativeLayout A,里面有两个LinearLayout B、C,而B中又有一个一个FrameLayout D。如果要在代码里设置B的LayoutParams,B的LayoutParams要为RelativeLayout.LayoutParams。
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); B.setLayoutParams(params);
而D要设置的话,需要:
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0); params.weight = 8; D.setLayoutParams(params);
而笔者是直接使用的最外层的RelativeLayout,它的外层不是RelativeLayout了,导致笔者的代码一直报错
java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams
所以笔者就在最外层的RelativeLayout放入了一个RelativeLayout_inside,然后再把自定义view放入RelativeLayout_inside,现在RelativeLayout_inside的外层就是RelativeLayout了,错误也就消失了。
现记录,引以为戒
0 0
- android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams
- android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
- android.widget.FrameLayout$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
- android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- android.app.ActionBar $LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams
- android.view.ViewGroup$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams
- Android异常:RelativeLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
- LinearLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- ViewGroup$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams错误提示
- android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutPara
- android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParam
- java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutPara
- android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParam
- android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParam
- java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widg
- java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widg
- Oracle的解锁和改密码
- PAT(A) - 1044. Shopping in Mars (25)
- 改bug不能只靠蒙——调试入门
- java异常处理
- NOIP2016Day2第2题 蚯蚓
- android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams
- 【38.24%】【POJ 1201】Intervals
- 遍历json对象的所有key,在使用json对象时,如果无法知道key,怎么通过key变量来获取值
- String、StringBuffer、StringBuilder浅析
- POJ 3167 Cow Patterns 已翻译
- OS之一句话去除UITableView底部多余行及分割线
- 浅谈DIP,IoC,DI,IOC容器
- 洛谷 P2670 扫雷游戏
- ThinkPHP实现文章上一篇和下一篇