2

I am using a ListView with just a few items. The items are to be vertically enlarged to fill the area given to the list view. So instead of:

_____
1
2
3


____

I want

_____

1
_

2
_

3
____

I am not sure how to do this. I looked at using getView on my Adapter, but the ViewGroup return 0 for the height, and 0 for the child count. When I make my adapter have a ListView reference, I can get the child count, but height is still 0.

I'm not sure if I need to extend ListView or ViewGroup or what I need to override.

Thanks.


After much digging, i found the issue is the mysterious Layout Inflater issue described here. Once I changed it to inflate(layoutIdToInflate, parent, false); (having been inflate(layoutIdToInflate, null); the heights started working.

Community
  • 1
  • 1
Scorp1us
  • 21
  • 3
  • 1
    This older post asks the same question https://stackoverflow.com/questions/11044595/listview-to-cover-entire-screen-in-android – user7610 Mar 31 '14 at 14:47

1 Answers1

0

You can't do that with ListView via xml. But you can set minHeight for your ListView item layout programmatically.

agamov
  • 4,407
  • 1
  • 27
  • 31
  • Thanks, but how can I even do the minHeight calculation? I can get the count, but the height of the ListView as far as I can tell is always 0. – Scorp1us Mar 31 '14 at 14:56
  • get the height of the `ListView` container. – agamov Mar 31 '14 at 15:18
  • It always returns 0. ` int count = mContentListView.getCount(); int height = mContentListView.getHeight();` count =5, height = 0; – Scorp1us Mar 31 '14 at 15:40
  • no, I meant the parent view of your `ListView`. Sorry, my English is bad). Or you can use `getMeasuredHeight()` method. – agamov Mar 31 '14 at 15:53