title: Android ListView fixed height item
body: <p>Got a little problem. I'd like to create an android list view activity with all items in the list having a fixed height.</p>
  
  <p>So, my item layout (thread_item.xml) looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="300dip"
          &gt;
      &lt;TextView android:id="@+id/thread_item_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="[dummy]"
                android:textSize="20dip"
                android:textStyle="bold"
              /&gt;
      &lt;ImageView android:id="@+id/thread_first_image"
                 android:layout_below="@id/thread_item_title"
                 android:scaleType="centerInside"
                 android:maxWidth="100dip"
                 android:maxHeight="100dip"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:adjustViewBounds="true" /&gt;
      &lt;TextView
              android:id="@+id/thread_item_preview"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignTop="@id/thread_first_image"
              android:text="[dummy]"
              android:textSize="15dip"&gt;
      &lt;/TextView&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>I set layout_height of the root element to 300dip and expect all items to have the same height, but they don't. When I run the application it looks like the height having a wrap_content value.</p>
  
  <p>In addition the activity itself looks like this:</p>
  
  <pre><code>public class ThreadListActivity extends ListActivity {
  
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);        
          /*
           Code to get items from the storage.
          */
  
          setListAdapter(new ThreadItemAdapter(this, R.layout.thread_item, itemsArray)));
  
  
          getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int position, long id) {
                  /*Start new Activity. Unrelated stuff.*/
              }
          });
      }
  }
  </code></pre>
  
  <p>And adapter I'm using looks like this:</p>
  
  <pre><code>public class ThreadItemAdapter extends ArrayAdapter&lt;ThreadItem&gt; {
  
      Activity context;
      List&lt;ThreadItem&gt; items;
  
      public ThreadItemAdapter(Activity context, int textViewResourceId, List&lt;ThreadItem&gt; items) {
          super(context, textViewResourceId, items);
          this.context = context;
          this.items = items;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          LayoutInflater inf = this.context.getLayoutInflater();
          View result;
          if (convertView == null) {
              result = inf.inflate(R.layout.thread_item, null);
          } else {
              result = convertView;
          }
  
          TextView tbTitle = (TextView) result.findViewById(R.id.thread_item_title);
          TextView tbPreview = (TextView) result.findViewById(R.id.thread_item_preview);
          ImageView ivFirstImage = (ImageView) result.findViewById(R.id.thread_first_image);
  
          ThreadItem item = items.get(position);
  
          tbTitle.setText(item.getThreadTitle());
          ivFirstImage.setImageBitmap(item.getFirstImage());
  
          SimpleLeadingMarginSpan span = new SimpleLeadingMarginSpan(item.getFirstImage() != null ? 5 : 0, 115); // TODO: const
          SpannableString previewText = new SpannableString(item.getThreadPreview());
          previewText.setSpan(span, 0, previewText.length(), 0);
          tbPreview.setText(previewText);
  
          return result;
      }
  }
  </code></pre>
  
  <p>I can't see why all list items still wrap their content and don't stay 300dip in height. They might be both smaller or bigger then 300dip.
  I'm using android 2.3.3, testing on HTC Evo 3D device and an emulator (both show same result).</p>
  
  <p>Thanks a lot in advance.</p>
  
  <p><strong>UPD:</strong></p>
  
  <p>Thanks to Miguel and Sam. The solution is to set maxHeight to the textView, that makes my list item grow (that would be <code>+id/thread_item_preview</code>) and setting the RelativeLayout's minHeight to 300dip as well, to prevent it from shrinking.</p>