Skip to content

Instantly share code, notes, and snippets.

@Reacoder
Created July 24, 2014 06:24
Show Gist options
  • Save Reacoder/c099a85eb3b229ddc9aa to your computer and use it in GitHub Desktop.
Save Reacoder/c099a85eb3b229ddc9aa to your computer and use it in GitHub Desktop.
Android ListView fixed height item
short answer:
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);
explanation:
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. supplying the parent view, and passing false will honor the 300dip height, while telling the inflater to not attach it to the root (parent), which the listview should be doing automagically by itself.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment