Android 在自定义view中动态设置布局规则

来源:互联网 发布:打字的软件下载 编辑:程序博客网 时间:2024/06/09 18:41
private RelativeLayout.LayoutParams layoutParams;
layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);layoutParams.bottomMargin = -dip2px(context,200);setLayoutParams(layoutParams);

public static int dip2px(Context context, float dpValue) {    final float scale = context.getResources().getDisplayMetrics().density;    return (int) (dpValue * scale + 0.5f);}

0 0
原创粉丝点击