Zsombor Erdődy-Nagy
Zsombor Erdődy-Nagy

Reputation: 16914

How can I scroll ListView continually with a constant velocity from code?

I have a ListView in which the user can drag&drop list elements to reorder the list (android 3.0). However, I have to handle the case when the list is long, and the user has to be able to scroll it during dragging an item. So I've put two scroll-areas onto the screen, one at the top and one at the bottom. When the user drags an item onto these, the ListView should start to scroll up/down with a constants speed, as long as the dragged item is in these areas.

How can I achieve this scrolling with ListView?

I've tried the smoothScroll...() methods but they need a specific position in the list to scroll to, or a specific distance to scroll by. The standard scrollBy...() methods don't work either, they scroll the ListView, but don't appear to invalidate is properly, so the appearing rows don't get rendered.

Any ideas?

Upvotes: 1

Views: 1730

Answers (2)

jhansi
jhansi

Reputation: 548

You could try smoothScrollToPositionFromTop(int position, int offset, int duration) with varying duration depending on the position where to scroll, like say

int duration = position*100;

Upvotes: 1

A. Abiri
A. Abiri

Reputation: 10810

You could try listView1.smoothScrollByOffset(int viewPosition). This way you could make the listview scroll up and down by an interval of 1+ views.

Upvotes: 1

Related Questions