java.lang.ClassCastException: 。。。$LayoutParams cannot be cast to android.widget.LinearLayout$Layout
来源:互联网 发布:淘宝邻家好货 编辑:程序博客网 时间:2024/05/16 09:53
今天经理说自己做的按钮在高分辨率的屏幕上显示的太小,就决定根据分辨率的大小,按钮的背景图片宽高比设置按钮的宽和高:
LayoutParams params=new LayoutParams(imgWidth,imgHeight); navi_bt.setLayoutParams(params);
但是运行时报了:java.lang.ClassCastException: 。。。$LayoutParams cannot be cast to android.widget.LinearLayout$Layout查了网上的资料才知道,当代码设置控件参数时,LayoutParams的类型必须是负控件的参数类型,即:如果负控件的类型为RelativeLayout,那么应该是RelativeLayout.LayoutParams,然后就把代码改成了一下:
RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(imgWidth,imgHeight); navi_bt.setLayoutParams(params);
确实可以了。再次做下笔记
0 0
- java.lang.ClassCastException: 。。。$LayoutParams cannot be cast to android.widget.LinearLayout$Layout
- 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.wi
- 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.wi
- 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.widg
- android异常总结--java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast t
- java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutPara
- java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
- java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.LinearLayout
- 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.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.wid
- Android studio导入eclipse项目
- 检测出来的结果怎么会是这样。。
- pcap网络抓包 无法import pcap
- bind1st与bind2nd函数解析
- AndroidのListView包含CheckBox时滑动丢失选中状态的解决
- java.lang.ClassCastException: 。。。$LayoutParams cannot be cast to android.widget.LinearLayout$Layout
- 全面理解面向对象的 JavaScript
- Android NDK (学习笔记五) —— java层和native层进行字符串的交互处理
- list常用函数的例子
- Android 利用sharepreference保存应用程序状态
- Laravel 4 Tutorial / Add_Twitter-Bootstrap
- C++ 容器及选用总结
- Android Design Support Library使用详解
- 传智播客Android7.16日入驻大广州