需要以编程方式将左边距设置为按钮对象。这是代码段:
RelativeLayout rl = (RelativeLayout) findViewById(R.id.for_button);
MarginLayoutParams ml = new MarginLayoutParams(-2,-2);
ml.setMargins(5, 0, 0, 0);
Button btn = new Button(this);
btn.setText("7");
btn.setTextColor(Color.WHITE);
btn.setBackgroundResource(R.drawable.date_button);
rl.addView(btn,ml)
我也试过
btn.setLayoutParams(ml);
rl.addView(btn);
什么大问题。或者有什么替代方法吗?