title: Add images to linearlayout programmatically
body: <p>I have a <code>HorizontalScrollView</code>with a <code>LinearLayout</code> in it and I want to add multiple images to layout programmatically with all of them in same height (about 300dp) and wrap content. something like they are fitted in the scroll area by scale. 
  My problem is when the View is loaded there is only one image in scroll area and other images become visible by scrolling.
  Think like 4 images and there is only one visible with blank area around it (The first) but the other 3 are correctly added after each other.
  Here is my Code</p>
  
  <pre><code>            &lt;HorizontalScrollView
                  android:id="@+id/gallery_scroll"
                  android:layout_width="fill_parent"
                  android:layout_height="300dp" &gt;
  
                  &lt;LinearLayout
                      android:id="@+id/gallery_layout"
                      android:layout_width="wrap_content"
                      android:layout_height="match_parent"
                      android:orientation="horizontal" &gt;
  
                  &lt;/LinearLayout&gt;
              &lt;/HorizontalScrollView&gt;
  </code></pre>
  
  <p>and the adding function : </p>
  
  <pre><code>for (final GalleryItem item : items) {
      ImageView iv = new ImageView(context);
      LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT
                                              , LayoutParams.MATCH_PARENT);
  
       param.setMargins(0, 0, 10, 0);
       iv.setLayoutParams(param);
       iv.setImageBitmap(item);
       layout.add(iv);
  }
  </code></pre>
  
  <p>the result : 
  <img src="https://i.stack.imgur.com/lSu30.png" alt="enter image description here"></p>