Skip to content Skip to sidebar Skip to footer

Listview Background Scroll With Data

Is it possible to make a background stretch over the whole ListView, instead of just staying on a fixed position? I remember in CSS when making websites you could make the backgrou

Solution 1:

Using a stock ListView to do what you want would not be possible.

ListView only displays a few rows at a time in order to save on View creation/management/etc. that could bog the system down. As a result, the ListView doesn't even know the total height of itself - it doesn't render a row until that row is visible, and rows can vary in height. If it doesn't even know its own height, how could it have a background that spans the entirety of it?

That said, your idea of using a ScrollView would be possible. However, you would then be losing out on ListView's optimization - if you only had few rows, then this isn't a big deal; but if you're talking about dozens of rows (or more), then your app may seriously chug. Also, you don't get ListView's framework, which is geared towards making an easier row-based UI.

It would be possible to write your own ListView subclass (or custom ListView) that can calculate its total height (so long as you know that each row is of a fixed height), then draw the background accordingly. That is probably what I'd do if I was required to do what you describe and had too many rows to just stuff into a ScrollView comfortably.

Post a Comment for "Listview Background Scroll With Data"