$LayoutParams cannot be cast to $LayoutParams

时间:2025-02-09 09:37:20

今天在实现动态改变布局的时候,报了个Error<$LayoutParams cannot be cast to $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 ((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)));
不能粗心不能粗心,要仔细!