LinearLayout.setLayoutParams置动态设置的左右边距报错解决方案

1.RelativeLayout 设置边距使用此方法可以但是LinearLayout.setLayoutParams 就报错类型转换错误
RelativeLayout.LayoutParams hint_page_params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
hint_page_params.setMargins(setWith,0, setWith, 0);//设置左右边距
hint_page_params.addRule(RelativeLayout.BELOW, 1); //设置位置

login_content_show_rl.setLayoutParams(hint_page_params);


2.LinearLayout.setLayoutParams  必须使用FrameLayout.LayoutParams设置参数

FrameLayout.LayoutParams  hint_page_params = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
hint_page_params.setMargins(setWith,ActivityUtil.dip2px(context, 20), setWith, 0);//设置边距
register_parent_rl.setLayoutParams(hint_page_params);

你可能感兴趣的:(android)