6 ms·
My experience with ListView was... weird. It doesn't ask you for a height for each row like UITableView does, just for a row count. Then, it measures your views
by nsmnsf 13y ago
My experience with ListView was... weird. It doesn't ask you for a height for each row like UITableView does, just for a row count. Then, it measures your views as you return them. This meant that the scrollbar was completely unreliable, it would resize based on the height of the currently visible views. Is there an obvious way around this that I'm missing? ListAdapter doesn't have anything for specifying height.
- weaksauce 13y agoSomething like this[1] didn't work for you? [1] http://stackoverflow.com/questions/15039913/android-how-to-measure-total-height-of-listview http://stackoverflow.com/questions/15039913/android-how-to-m...
- srcreigh 13y agoThis is by design in Android. It's very computationally heavy to ask for the heights of each ListView item. Unfortunately I wasn't able to dig up my reference to this. :( Two more things: 1. The wormy scrollbar is actually standard on Android: the messaging app does it, IIRC even the twitter app on Android does it. So even though your iOS experience tells you it's weird, any users of yours on Android likely won't notice. 2. If your items are all the same height then your scrollbar won't be wormy. So if this is really that important to you, then make your ListView return items that all have the same height.
- xsmasher 13y ago> It's very computationally heavy to ask for the heights of each ListView item. Can you expand on that? Do you mean that it's expensive for the OS for some reason, or do you mean that it's expensive for your (client) code to compute the height of each item? It seems like in most cases it's a simple method like "return isHeader : HEADER_HEIGHT : ITEM_HEIGHT;"
- BitMastro 13y agoFor the OS. Imagine 999 rows containing one line of text and the last one containing a long text spanning maybe 30 lines. To calculate the scroll accurately you need to calculate the height of 1000 elements to get the full height. Instead in the common scenario you just calculate the height of the rows displayed on the screen and estimate the height using the average and the count.
- nsmnsf 13y agoI don't have to imagine this, though, I've done it on iOS. It works fine, because you're rarely working with 1000 items at once. With pagination, you cache the old results, and only calculate the new 50 or so rows at a time.
- BitMastro 13y agoOn the other end, pagination is rarely used on Android, and calculating the height of a single row can be more expensive since it has to layout the children hierarchy for a row according to the screen dimensions.
- nsmnsf 13y agoThis type of layout is generally limited to social feeds, where pagination is pretty much mandatory (you have to request more results from an API). Anything entirely client-side typically uses fixed height rows.
- BitMastro 13y agoI see your point, but this layout is used also for variable height images, variable lenght text, compound layouts, etc. The equivalent of pagination on Android is usually done using pull to refresh (horizontal swipe gestures are usually used to change topics more or less). For something completely client side it is possible either to specify a fixed height or change the smoothScrollbar attribute of the listview (it is more expensive though and not used very much). Nobody complains, I guess everyone is just used to the way it is. :D