开发者

Attaching a fixed, transparent, header to a ListView?

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:

Attaching a fixed, transparent, header to a ListView?

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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜