How to scroll down to the footer of a list view and show the whole footer

时间:2015-11-12 12:09:45

标签: android listview android-listview

I have a long list with a big header and footer and I need to scroll the list all the way down and show the whole footer. Also, items can have very different height so the overall height cannot be simply calculated height * no items.

All the existing questions I've seen do not take in account the footer might be big and not entirely shown when scrolling to last position.

So far I've tried:

1) the simplest solution:

lv.setSelection(lv.getCount() - 1);

However this will not show the whole footer, only part of it and I need to have it all visible.

2) using:

requestFocus();

on the footer, the main layout in it, and any elements in the footer: this changes the focus but doesn't force the listview to scroll down.

3) using:

lv.scrollTo(x, y);

problem with this is that I couldn't get the real height of the listview in a reliable way as items are not fixed size. Beside, after scrolling often part of the list is not shown leaving a wide white area.

4) header and footer are contained in two adapters but I couldn't figure out how to reach them to be shown on the screen

5) I have also tried a mixed approach:

lv.setSelection(lv.getCount() - 1);
lv.scrollListBy(mFooter.getHeight());

But the scrollListBy() doesn't seem to have any effects after a setSelection - not sure why.

Does anyone have any suggestions?

Thanks in advance

0 个答案:

没有答案