4

I have a ListView with header and I need to set header size programmatically depending on screen size. So it fills nearly whole screen. How can I do that? I found a way to get screen height, but it is the full height of the display, containing phone status bar height.

Graykos
  • 1,281
  • 3
  • 20
  • 31

1 Answers1

6

if you are setting the header to the ListView by inflating a layout, like this:

ListView lv = getListView();
LayoutInflater inflater = getLayoutInflater();
ViewGroup header = (ViewGroup)inflater.inflate(R.layout.header, lv, false);
lv.addHeaderView(header, null, false);

you can change the height of the layout R.layout.header using

header.setLayoutParams(params);

You can get Notification or Status Bar height using this code here:

Height of statusbar?

Community
  • 1
  • 1
Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226
  • the question is mostly not about setting the height, but about getting it. I can get the full height of the display (480x800 on my phone), but i need to set header height to . So I need to get notificationBarHeight, cause I suppose it could differ between different devices. – Graykos Sep 11 '12 at 08:35
  • so you got your screen height, and smthElse, all you need is notificationBarHeight? I mean what height you exactly want? – Archie.bpgc Sep 11 '12 at 08:36
  • yes, you may say I need notificationBarHeight. But I dont want to hardcode it, cause, I suppose, it may vary between different devices – Graykos Sep 11 '12 at 08:45
  • check the link provided in the answer – Archie.bpgc Sep 11 '12 at 08:56