title: How to make space between LinearLayout children?
body: <p>I am programatically adding custom views to a vertical LinearLayout, and I would like there to be some space between the views.  I have tried adding: setPadding(0, 1, 0, 1) to my CustomView constructor, but this doesn't seem to have any effect.  Any advice?</p>
  
  <p>*It was pointed out that I should use margins.  Since I am dynamically adding views, I need to set the margins from code (not in xml).  I believe the way to do this is below, but it isn't working.</p>
  
  <pre><code>public class MyView extends View
  {
      public MyView (Context context)
      {
          super(context);
  
          MarginLayoutParams params = new MarginLayoutParams(LayoutParams.WRAP_CONTENT,  LayoutParams.WRAP_CONTENT);
          params.setMargins(0, 10, 0, 10);
          setLayoutParams(params);
  </code></pre>
  
  <p>*Edit.  I also tried using MarginLayoutParams as a parameter while adding the views to the Linear layout (as below).  This also did not work:</p>
  
  <pre><code>MarginLayoutParams params = new MarginLayoutParams(linearLayout.getLayoutParams());
  linearLayout.setMargins(0, 10, 0, 10);
  linearLayout.addView(view, params);
  </code></pre>