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); //设置位置
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开发中,RelativeLayout与LinearLayout在设置布局参数时的不同之处,通过具体代码实例展示了如何在两个布局中分别设置边距,并解释了为何在LinearLayout中使用FrameLayout.LayoutParams更为合适。
3166

被折叠的 条评论
为什么被折叠?



