ClassCastException异常增加的LayoutParams时 [英] ClassCastException when adding LayoutParams

查看:220
本文介绍了ClassCastException异常增加的LayoutParams时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有哪些类使用,设定时,的LayoutParams 我的的LinearLayout ?下面的两个不工作

Which class do I have to use, when setting the LayoutParams of my LinearLayout? The following two are not working:

  1. linLayout.setLayoutParams(新ViewGroup.LayoutParams(50,50));
  2. linLayout.setLayoutParams(新android.widget.LinearLayout.LayoutParams(50,50));
  1. linLayout.setLayoutParams(new ViewGroup.LayoutParams(50,50));
  2. linLayout.setLayoutParams(new android.widget.LinearLayout.LayoutParams(50,50));

如果我第一次拿到了参数,可以改变它们,并将它们设置回它的工作。所以,我想我得到ViewGroup.LayoutParams ...

if I get the params first, change them and set them back it's working. So I suppose the Params I get returned inherit from ViewGroup.LayoutParams...

你知道吗? THX

推荐答案

使用母公司的的LayoutParams。所以,如果你的LinearLayout是RelativeLayout的一个孩子,那么你使用 linLayout.setLayoutParams(新android.widget.RelativeLayout.LayoutParams(50,50));

Use the LayoutParams of the parent. So in case your LinearLayout is a child of RelativeLayout then you use linLayout.setLayoutParams(new android.widget.RelativeLayout.LayoutParams(50,50));

这篇关于ClassCastException异常增加的LayoutParams时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆