如何设置我在java活动中创建的按钮的边距


Button button = new Button(All_HomeWork_List.this);
button.setBackground(getDrawable(R.drawable.orange_button) );
button.setTextSize(25);
buttonLay.addView(button);

您应该使用LayoutParams来设置按钮边距:

LayoutParams params = new LayoutParams(
LayoutParams.WRAP_CONTENT,      
LayoutParams.WRAP_CONTENT
);
params.setMargins(left, top, right, bottom);
yourbutton.setLayoutParams(params);

@mokhtar halim很抱歉,此代码目前不起作用。请检查照片,,,,setMargins问题显示在这里

相关内容

最新更新