title: Arrange multiple images (dynamically created) properly in a layout
body: <p>I have created an image and a video gallery where I'm retrieving images and videos saved at server side and displaying them in a <code>LinearLayout</code>.</p>
  
  <p>I'm creating <code>ImageView</code>, <code>VideoView</code>, <code>LinearLayout</code> &amp; <code>ScrollView</code> dynamically based on number of Images/Videos.</p>
  
  <p><strong>Code snippet:</strong></p>
  
  <pre><code>@Override
          protected void onPostExecute(Void aVoid)
          {
              Log.e("onPost", "..");
              int i;
  
              for(i=0;i&lt;list.size();i++)
              {
                  img = new ImageView(Image.this);
                  img.setImageBitmap(list.get(i));
                  img.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                  img.computeScroll();
                  img.setPadding(5, 5, 5, 5);
                  img.getLayoutParams().width=500;
                  img.getLayoutParams().height=300;
                  picLL.addView(img);
              }
              sv.addView(picLL);
              sv.setForegroundGravity(Gravity.BOTTOM);
              setContentView(sv);
              dialog.dismiss();
              super.onPostExecute(aVoid);
          }
  </code></pre>
  
  <p>This code displays all images one after another like this:</p>
  
  <p><img src="https://i.stack.imgur.com/wAams.png" alt="1"></p>
  
  <p>Same with videos.</p>
  
  <p>But it doesn't look good.I want them to be arranged as in gallery.like this:</p>
  
  <p><img src="https://i.stack.imgur.com/opHCN.png" alt="enter image description here"></p>
  
  <p>How could I achieve this.</p>
  
  <p>Any kind of suggestions would be of great help.<br>
  Thank you.</p>