title: MarginLayoutParams.setMargins() is not working?
body: <p>Here's the thing: I want to add some images programmatically. The images should have to have a <code>topMargin</code> of <code>5dip</code> except for the first image, in a <code>LinearLayout</code> with a <code>vertical orientation</code> manner. below the code segment: </p>
  
  <pre><code>LinearLayout body = (LinearLayout) findViewById(R.id.body);
  
      for (int i = 1; i &lt;= 4; i++) {
  
          ImageView img = new ImageView(this);
          MarginLayoutParams lp = new MarginLayoutParams(-2, -2);
  
          img.setImageResource(R.drawable.image);
          if (i != 1) {
  
              lp.setMargins(0, 5, 0, 0);
  
          }
          img.setLayoutParams(lp);
  
          body.addView(img);
          body.requestLayout();
      }
  </code></pre>
  
  <p>By running the program I can see the the 4 images(here) vertically aligned one by one but there is no <code>topMargin</code>(as in the code,<code>5dip</code>). <code>body</code> is the <code>id</code> of the <code>LinearLayout</code>. here's the <code>XML</code> segment to:</p>
  
  <pre><code>&lt;LinearLayout
              android:id="@+id/body"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="#901b0e08"
              android:orientation="vertical"
              android:paddingLeft="6dp"
              android:paddingRight="8dp" &gt;
   &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I cant get what went wrong here.</p>
  
  <p>Thanks.</p>