I am new to android and I want to retrieve button information which is in the XML file. (specifically margin\_top and margin\_left). After that, i want to dynamically give another margins to that specific button in cording. I can create new button with new margin but i cant retrieve current button margins..

Any help would be appreciated.

```
android.view.ViewGroup.LayoutParams lay = btn1.getLayoutParams();

```

this lay object hold all the information but i cant get margins from that.

i created my button using following code.

```
RelativeLayout layout = (RelativeLayout)findViewById(R.id.relativeTest);
        Button btn3 = new Button(TestActivity.this);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
        params.setMargins(200, 200, 200, 200);
        layout.addView(btn3, params);

```