android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
2016-12-08 10:27
507 查看
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的时候,遇上如题问题,
简单的举个栗子说明一下:最外层有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);
可以解决了,分享给大家
相关文章推荐
- android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
- android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
- android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
- ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.AbsLis
- 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
- LinearLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- Android异常:RelativeLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
- java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.wid
- java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.wid
- java.lang.ClassCastException: 。。。$LayoutParams cannot be cast to android.widget.LinearLayout$Layout
- :java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.wi
- android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutPara
- android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widg
- android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams