Android动态添加控件约束位置

来源:互联网 发布:mysql work导出数据库 编辑:程序博客网 时间:2024/05/16 20:29
用LayoutParams: RelativeLayout insertLayout = (RelativeLayout)view1.findViewById(R.id.screen);//screen是一个RelativeLayout 布局的idImageView imgApple2 = new ImageView(MainActivity.this);        imgApple2.setBackgroundColor(Color.parseColor("#ffb6b4"));RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(100, 100);        layoutParams.topMargin=8;        layoutParams.leftMargin=8;        layoutParams.rightMargin=8;        layoutParams.bottomMargin=8;insertLayout.addView(imgApple2,layoutParams);
0 0
原创粉丝点击