title: Android first ImageView in vertical LinearLayout stretching
body: <p><a href="https://i.stack.imgur.com/4PRWs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4PRWs.png" alt="The current popup"></a></p>
  
  <p>I'm creating the above popup, the content of which consists of rows of horizontal LinearLayout views within a main vertical LinearLayout. Each horizontal LinearLayout contains one ImageView and one TextView.
  I'm creating this within a PopupWindow, and doing so programmatically so that I can change the ImageView source as required.</p>
  
  <p>As you can see the first icon seems to take up a lot of space, despite having the same code generating it as the other icons.</p>
  
  <p>Below is the code:</p>
  
  <pre><code> LinearLayout verticalLayout = new LinearLayout(context);
          verticalLayout.setOrientation(LinearLayout.VERTICAL);
  LinearLayout.LayoutParams mainLayoutParams =
                  new  LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
  verticalLayout.setLayoutParams(mainLayoutParams);
  
  LinearLayout.LayoutParams layoutParams =
                  new  LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  LinearLayout.LayoutParams iconParams =
                  new  LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
  LinearLayout.LayoutParams textParams =
                  new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  
  //History row
  LinearLayout historyLayout = new LinearLayout(context);
  historyLayout.setLayoutParams(layoutParams);
  historyLayout.setOrientation(LinearLayout.HORIZONTAL);
  ImageView historyIcon = new ImageView(context);
  historyIcon.setImageResource(R.drawable.small_book_grey);
  historyIcon.setAdjustViewBounds(true);
  historyIcon.setLayoutParams(iconParams);
  historyLayout.addView(historyIcon);
  TextView historyText = new TextView(context);
  historyText.setLayoutParams(textParams);
  historyText.setText("History");
  historyLayout.addView(historyText);
  verticalLayout.addView(historyLayout);
  
  //Exam row...
  //... (duplicate of history row)
  </code></pre>
  
  <p>I've tried playing around with the layout parameters, even creating a mock xml layout that displays the content as I'd like, to match the parameters to.
  If anyone can give some advice on making that book icon the same size as the others, I'd be grateful.</p>