如何在Relativelayout中动态设置控件位置
1个回答
展开全部
用LayoutParams:
RelativeLayout insertLayout = (RelativeLayout)view1.findViewById(R.id.screen);//screen是一个RelativeLayout 布局的id
ImageView 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);
RelativeLayout insertLayout = (RelativeLayout)view1.findViewById(R.id.screen);//screen是一个RelativeLayout 布局的id
ImageView 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);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询