ClassCastException异常增加的LayoutParams时异常、ClassCastException、LayoutParams

2023-09-05 07:13:31 作者:卧在花台下赏花

我有哪些类使用,设定时,的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));