I though this would be a simple task, but apparently there is no way to scroll listview to the bottom. All solutions that I found are using variations of setSelection(lastItem)
method which only sets selection to last item, but does not scrolls to the bottom of it.
In my case I have a empty listview (with a long empty view header set) and I want to scroll to bottom of it.
So, is there a way to do it?
Edit:
So for those who are interested the working solution is:
getListView().setSelectionFromTop(0, -mHeader.getHeight());
and
getListView().scrollTo(mOffset)
This also works, with right offset (calculated based on current scroll position), but might give you some unexpected results.
All you have to do is set Global Keys for your widgets and call Scrollable. ensureVisible on the key of your widget you want to scroll to. For this to work your ListView should be a finite List of objects. If you are using ListView.
If you want the list view to be scrolled always at the bottom even when you are updating the list view dynamically then you can add these attributes in list view itself.
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
use the following
lv.setSelection(adapter.getCount() - 1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With