Android ListView fixed height item
Try changing this
android:layout_height="300dip"
to
android:minHeight="300dip"
This worked for me using an ExpandableListView, so I suppose it will work for this case.
when inflating for convertView, instead of just
result = inf.inflate(R.layout.thread_item, null);
do
result = inf.inflate(R.layout.thread_item, parent, false);
The method in question is inflater.inflate(int viewId, ViewGroup parent, boolean attachToRoot)
-- because you're not honoring the supplied parent
(which in this case is the ListView), whatever dimension you supply to the listview item will by default be set to layout_width=fill_parent, layout_height=wrap_content, ignoring the 300dip height you specified in xml. By supplying the parent view and passing false
, the inflater will honor the 300dip height, while not attaching it to the root (parent).
You can achieve this by specifying the same dimension for Min and Max. This fixed my problem.
<ImageView
android:id="@+id/appIconImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:adjustViewBounds="true"
android:maxHeight="50dp"
android:maxWidth="50dp"
android:minHeight="50dp"
android:minWidth="50dp"
android:src="@drawable/ic_launcher" />
What if you change all the child view heights in the row from wrap_content
to match_parent
?
From comments
Have you tried the minHeight
and maxHeight
attributes? For example:
android:minHeight="300dp"
You should also watch Android's Romain Guy discuss efficiency in adapters and getView()
.