java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.wid
来源:互联网 发布:苹果6s无法加入网络 编辑:程序博客网 时间:2024/05/21 09:48
转载的别人的,原博客地址:http://blog.csdn.net/lilu_leo/article/details/11952717
有时候需要在在代码中设置LayoutParams,自己为一个FrameLayout设置LayoutParams的时候,遇上如题问题,
- java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
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);
这样问题即可解决。还是自己有些基础知识不牢固,写到此。
0 0
- java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.wid
- 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: 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: android.widget.FrameLayout$LayoutParams cannot be cast to android.widg
- 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.....
- java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widg
- java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.wid
- java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutPara
- java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.L
- java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.w
- java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.
- java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.R
- java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.w
- java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.w
- java.lang.ClassCastException: android.app.ActionBar$LayoutParams cannot be cast to android.widget.Ab
- 上海道瑞网络科技公司
- Linux网络编程 之 UDP 组播实例
- 百度地图开发(一)——概述
- 多个域名重定向(301)到一个域名 Apache
- android--笔记--自动解析xml
- java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.wid
- C#读写配置文件(.config)简介
- Ubuntu下rpm包转deb包
- 打造最强大的vim IDE(一) —— vim管理插件的插件
- 考计算拉三JDK等解锁
- Java多线程(一)、多线程的基本概念和使用
- poj 3026 Borg Maze
- ios硬件采集信息汇总
- 一个字符串显示多种颜色