1

I have a ListView which I want to look like a card. I have a 9-patch to use as a background that achieves the raised card look.

In the likely chance it's larger than the screen, I'd want to be able to see a top margin above my card background, and when I scroll down the list, the margin should be pushed up off the screen. When I scroll to the bottom, I should similarly see the bottom margin appear.

ListView.addHeaderView() and .addFooterView() don't cut it in my case, because those become part of backing ListAdapter and get drawn within the bounds of my card background.

I've seen a technique that would work - wrapping my ListAdapter with one that decorates each item with elements of the card background I'd want. In this approach, each item draws a part of the card background.

However, this is less efficient than I'd like and it doesn't seem like logic that belongs in a ListAdapter. Instead I'm looking for a way to extend ListView to add this behavior, but I find myself getting lost while trying to read the 10,000 lines (seriously) of code in AbsListView and ListView.

I think pretty much the same question was asked a year ago here, but it got no answer: (Android) How to fill ListView background and preserve header transparency

EDIT

Another way to view this problem: is there a way to make the background scroll along with the list items? I think the answer is no - I believe the background (i.e. the ListView widget) is positioned fixed with respect to the screen, rather than the scrollable content within. If I'm on the right track with this thinking, then it would appear that the ListAdapter-with-partial-backgrounds-per-item approach is the only viable one.

4

0 回答 0