java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.w
报错日志:报错代码:场景:调整左右边距时报错。
·
报错日志:
报错代码:
场景:调整左右边距时报错
LinearLayout.LayoutParams lp =
(LinearLayout.LayoutParams) lightNavStartNavFocusArea.getLayoutParams();
lp.leftMargin = leftMargin;
lightNavStartNavFocusArea.setLayoutParams(lp);
解决方法:使用ViewGroup.MarginLayoutParams 代替 LinearLayout.LayoutParams
ViewGroup.MarginLayoutParams lp =
(ViewGroup.MarginLayoutParams) lightNavStartNavFocusArea.getLayoutParams();
lp.leftMargin = leftMargin;
lightNavStartNavFocusArea.setLayoutParams(lp);
使用该原因:该场景主要用于调整左右margin边距
而不管是线性布局,还是相对布局都继承自ViewGroup.MarginLayoutParams
更多推荐
已为社区贡献9条内容
所有评论(0)