ClassCastException异常增加的LayoutParams时 [英] ClassCastException when adding LayoutParams
问题描述
我有哪些类使用,设定时,的LayoutParams
我的的LinearLayout
?下面的两个不工作
Which class do I have to use, when setting the LayoutParams
of my LinearLayout
? The following two are not working:
-
linLayout.setLayoutParams(新ViewGroup.LayoutParams(50,50));
-
linLayout.setLayoutParams(新android.widget.LinearLayout.LayoutParams(50,50));
linLayout.setLayoutParams(new ViewGroup.LayoutParams(50,50));
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屋!