Android set margin of buttons declared in xml file programmatically?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/2481455/set-margins-in-a-linearlayout-programmatically">Set margins in a LinearLayout programmatically</a>  </p>
</blockquote>



<p>I have bunch of widgets in my layout.I have set layout_marginTop in layout file but I want to call these two buttons in activity and set layout_marginLeft and change the value programmatically.i tried with getLayoutParams() but can not set margin.
is it possible to change margin of widgets declared in xml file programmatically(after calling layout in the activity)?  </p>

<p>//oncreate method</p>

<pre><code>setContentView(R.layout.gamelayout);
</code></pre>

<p>//xml layout
</p>

<pre><code>    &lt;ImageView
        android:id="@+id/gameImage"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
     &gt;
    &lt;/ImageView&gt;

    &lt;Button
        android:id="@+id/lButton"
        android:layout_width="wrap_content"
        android:layout_height="140dip"
        android:layout_marginTop="10dip"
        android:layout_gravity="center_vertical|center_horizontal" /&gt;

    &lt;Button
        android:id="@+id/rButton"
        android:layout_width="wrap_content"
        android:layout_height="140dip"
        android:layout_marginTop="10dip" 
        android:layout_gravity="center_vertical|center_horizontal" /&gt;

    &lt;ImageView
        android:id="@+id/levelImage"
        android:layout_width="60dip"
        android:layout_height="60dip"
        android:layout_gravity="bottom|left"
        android:src="@drawable/ic_launcher" /&gt;

    &lt;Button
        android:id="@+id/homeButton"
        android:layout_width="60dip"
        android:layout_height="60dip"
        android:layout_gravity="bottom|right"
        android:background="@drawable/home_btn" /&gt;
&lt;/FrameLayout&gt;
</code></pre>

<p>please help me</p>

<p>thank you</p>
