2

I've been trying to get this working for some time... Is there any way to put a transparent fixed header on a listview, so it looks kind of like this:

Transparent sticky header

As you scroll up, the header will eventually be a regular header with item 1 below it.

I guess I'll have to implement onScrollListener and do something like when the first visible item is item 2 in the list, start moving the listview margins by 1 pixel, until it is below the header? Or are there better ways? Any ideas on how one would do something like that?

AmITheRWord
  • 1,363
  • 2
  • 14
  • 36

2 Answers2

5

I would make a FrameLayout... and put your ListView in it first, filling the screen. Then put a TextView on top of that. To get the desired behavior at the top, maybe have a blank element at position 0 of the list, or just make the top padding of list item 0 have the height of your header...

Does that make sense? The ListView should scroll underneath the TextView in a FrameLayout.

Matt
  • 3,837
  • 26
  • 29
  • This seems like a good solution. Rather than just adding a blank element though, my suggestion would be to use `addHeaderView()` on your ListView to add a blank View that's the same size as your header. – Kevin Coppock Jan 19 '11 at 16:08
  • It does make sense. Padding doesn't work though because my views have background colors, so I ended up adding a blank view the same size as my header with addheaderview as kcoppock suggested. – AmITheRWord Jan 19 '11 at 16:18
2

You can use a RelativeLayout for that, so you can get the Z axis using some properties;)

Update:

For example using a RelativeLayout:

RelativeLayout
----ListView
----TransparentHeader

Will appear in the way you show on your image.

As a comment :Android put layout elements in the order that they are defined on your xml, so, widgets at the bottom of the layout will be at the top.

yeradis
  • 5,235
  • 5
  • 25
  • 26
  • The Frame Layout will take advantage of the Z axis by default in declaration order in your XML, whereas Relative Layout does not. – Simon.Ponder Jun 18 '13 at 14:40