0

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

Tim Cooper
  • 151,519
  • 37
  • 317
  • 271
Ronnie
  • 11,008
  • 20
  • 76
  • 138
  • 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
  • 4,003
  • 6
  • 30
  • 56