title: Set size of ImageView in px at runtime
body: <p>I want to put 8 image thumbs in one horizontal line, using the whole available width.<br>
  The images are retrieved from a webservice which lets me specify the dimensions.<br>
  I tried the following:</p>
  
  <pre><code>int widthPx = container.getWidth();
  LinearLayout thumbs = (LinearLayout)curView.findViewById(R.id.thumbs);
      for(int i=0; i&lt;pics.length; i++) {
          ImageView iv = new ImageView(mContextt);
  
          int thumbSize = widthPx / 8;
  
          try {
              String url = "http://someurl/" + pics[i] + "&amp;width=" + thumbSize  + "&amp;height=" + thumbSize;
              URL imgUrl = new URL(url);
              Drawable imgD = Drawable.createFromStream(imgUrl.openStream(), "src");
              iv.setImageDrawable(imgD);
          }
          catch (Exception e) {
              Log.e(TAG, "loading image failed");
              e.printStackTrace();
          }
  
          thumbs.addView(iv);
      }
  </code></pre>
  
  <p>The LinearLayout thumbs has android:layout_width="fill_parent set. The thumbs produced by this code are significantly smaller then 1/8 of the width. Why is this? What would be the correct way?
  <br><br>
  Update:<br>
  This code is inside <em>onCreateView</em> of a Fragment. While my width value is calculated based on the root-view and is correct, <em>thumbs.getWidth()</em> returns 0, although the view is inflated before and should also have a width of 480 because of layout_width is set to fill_parent. I'm not sure if that's a problem.<br><br></p>
  
  <p>Is my assumption correct that the layout of the created ImageViews is set to wrap_content by default? If not, how to set this with Java code?</p>