首页 > 解决方案 > Android:如何在添加的按钮之间添加空格

问题描述

正如标题所述,我想在添加的按钮之间添加一些空间。

代码:

ConstraintLayout cst= (ConstraintLayout) findViewById(R.id.idButtonset);
cst.addView(this.addButton("Buttname0", R.id.svId));

Button fbutton= new Button(this);
fbutton.setText("Button 1");
Button sbutton = new Button(this);
sbutton.setText("Button 2");
cst.addView(fbutton);
cst.addView(sbutton);

问题:它将按钮添加到彼此之上。

我尝试了什么

fbutton.setPadding(30,30,30,30);
sbutton.setPadding(40,35,40,35);

问题:不支持边距,填充 - 有效,但它没有在添加的按钮之间创建空间。

问题:如何添加 Buttons 以在它们之间添加空格?

标签: androidxmlandroid-studiobutton

解决方案


推荐阅读