我动态创建了很多按钮。如何在两个按钮之间添加空格。请帮我。提前致谢
我的代码:
private LinearLayout LLDynamic;
private RelativeLayout.LayoutParams ParaOne;
ParaOne = new RelativeLayout.LayoutParams(280, 30);
Button button1= new Button(Twindo_fromEditGroup.this);
button1.setTextSize(16);
LLDynamic = new LinearLayout(Twindo_fromEditGroup.this);
LLDynamic.setOrientation(LinearLayout.VERTICAL);
LLDynamic.addView(button1,ParaOne);
答案 0 :(得分:5)
使用LayoutParams Study here for LinearLayout
您也可以使用RelativeLayout Params See here
然后你可以使用setMargins()。最后将这些值设置为动态创建的按钮。我没有发布任何代码。代码示例已在Nunu的帖子中给出。
快乐编码:)
答案 1 :(得分:0)
您可以添加边距..例如..
Button button1 = new Button(this);
LinearLayout.LayoutParams rel_button1 = new LinearLayout.LayoutParams(buttonWidth, buttonHeight);
rel_button1.setMargins(20, 0, 0, 0);
button1.setLayoutParams(rel_button1);
答案 2 :(得分:0)
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.setMargins(10, 0, 0, 0);
params.setLayoutParams(urButton);