Created
July 24, 2014 06:24
-
-
Save Reacoder/c099a85eb3b229ddc9aa to your computer and use it in GitHub Desktop.
Android ListView fixed height item
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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