0

In my layout xml, if I do something like android:layout_marginTop="10px", how can I do that same thing in java?

Ronnie
  • 11,138
  • 21
  • 78
  • 140
  • This question has been answered here: https://stackoverflow.com/questions/2481455/set-margins-in-a-linearlayout-programmatically – neteinstein May 17 '11 at 23:02

1 Answers1

0

Try this:

RelativeLayout rel=new RelativeLayout(this);
mWidth=getWindowManager().getDefaultDisplay().getWidth();
RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(mWidth,mHeight);
Button mBtn=(Button) findViewById(R.id.xBtn);
params=new RelativeLayout.LayoutParams(mWidth, mHeight);
params.setMargins(int left, int top, int right, int bottom);
mBtn.setLayoutParams(params);
Lavanya
  • 3,903
  • 6
  • 31
  • 57