The key to understanding what is happening is to find out how the ListView headers and footers are implemented. This is a trick: when you add the first header or footer to your ListView, your ListAdapter is wrapped in the HeaderViewListAdapter line (happens on line 270 of the ListView.java list ). HeaderListViewAdapter is a list adapter that adjusts the count and position values โโto include headers and footers; Headers and footers become regular list items that the system runs for you.
If you look at line 207 in HeaderListViewAdapter.java , you will see that the getView implementation ignores the parent view when adding a header or mLayoutParams its mLayoutParams not to be initialized from XML (actually cannot point to the source code, only what I discovered over time).
If you then follow the getView calls for bits, the last line 2237 from AbsListView.java and follow the obtainView calls for bits and find LayoutParams (this is what I just did), you get to line 1182 ListView.java . Here you can see that if the layout parameters are null when the child view is measured, it calls generateDefaultLayoutParams() , which is implemented on line 6065 of AbsListView.java :
@Override protected ViewGroup.LayoutParams generateDefaultLayoutParams() { return new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0); }
... and where your WRAP_CONTENT comes WRAP_CONTENT .
To make it easy, just wrap <LinearLayout/> your XML inside <FrameLayout/> . Store 500dp in LinearLayout and create a FrameLayout with the height of the layout WRAP_CONTENT (which will be ignored anyway).
Barend
source share