android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
来源:互联网 发布:面对疾风吧网络意思 编辑:程序博客网 时间:2024/04/30 11:45
今天在项目中就遇到这个问题,在一个父控件RelativeLayout中放置两个子控件ViewPager、LinearLayout,子控件LinearLayout中又有一个ListView控件,这样嵌套布局后,如果希望修改ViewPager的宽高,或者修改ListView的宽高时,我们将使用setLayoutParams(new LayoutParams)去修改,但是这其中的LayoutParams应该用哪一个才正确呢?
如果要设置RelativeLayout中LinearLayout的宽高,我们可能直接用:
RelativeLayout relativeLayout = new RelativeLayout(this);relativeLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));但是这样就会弹出以上错误了,我们不能使用LinearLayout下的Params,而应该使用父控件RelativeLayou下的Params。正确是:
RelativeLayout relativeLayout = new RelativeLayout(this);relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
同样的,ListView需要使用其父控件LinearLayout的Params。
0 0
- android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- LinearLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutPara
- android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.AbsListView$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.FrameLayout$LayoutParams
- 解决 android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- 报错:ViewPager$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- android.view.ViewGroup$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams
- Android异常:RelativeLayout$LayoutParams cannot be cast to android.widget.LinearLayout$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
- 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.RelativeLayout$LayoutParams cannot be cast to android.w
- Java垃圾回收浅析
- 取得指定日期是星期几
- C#模拟点击链接
- php性能优化的几个方法
- W5500问题集锦(二)
- android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- 女孩子工作中,可以把网页作为重点
- linux 时间同步
- C++ STL算法汇总
- Beginning Python From Novice to Professional (5) - 条件与循环
- Android推送方案分析(MQTT/XMPP/GCM)
- 在CentOS 7中安装与配置JDK8
- Linux tomca t图片服务器
- WebBrowser判断登录成功-WebBrowser-404错误-500错误-屏蔽消息窗口-Webbrowser判断是否加载成功