android.view.ViewGroup$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams

来源:互联网 发布:js所有方法 编辑:程序博客网 时间:2024/05/18 01:51

今天在实现动态改变布局的时候,报了个Error<android.view.ViewGroup$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams>


仔细去看了下代码,发现自己真的太粗心大意了,记下来,方便日后翻阅。


原代码:

ll_Pop_Params = ll_pop.getLayoutParams();

img_Product_Params = img_product_large.getLayoutParams();


ll_Pop_Params.width = (int) (width * 0.85);
ll_Pop_Params.height = (int) (width * 1.275);


ll_pop.setLayoutParams(ll_Pop_Params);
img_product_large.setLayoutParams(new ViewGroup.LayoutParams((int) (width * 0.85), (int) (width * 0.75)));

修改后:


ll_Pop_Params = ll_pop.getLayoutParams();
img_Product_Params = img_product_large.getLayoutParams();

ll_Pop_Params.width = (int) (width * 0.85);
ll_Pop_Params.height = (int) (width * 1.275);

ll_pop.setLayoutParams(ll_Pop_Params);
img_product_large.setLayoutParams(new RelativeLayout.LayoutParams((int) (width * 0.85), (int) (width * 0.75)));
不能粗心不能粗心,要仔细!


0 0
原创粉丝点击