Evgeniy S
Evgeniy S

Reputation: 1484

smoothScrollToPositionFromTop ignore duration parameter

My problem is smoothScrollToPositionFromTop method ignores duration parameter.

I'm try to use method for API > 10

listView.smoothScrollToPositionFromTop(position, listView.getHeight() - ROW_HEIGHT, 100);

What i expecting: scroll to the bottom with 100ms for any content Height.

What i get: it scroll to the bottom, but ignore my duration parameter.

If i set 10 or 100 or 1000 it will scroll with the same time.

If you need more details - just say what exactly detail you need and i will update with it.

UPD: It's works good with high duration (i try 11500) and it was really looong. But if i set 300 or lower it scroll like ~1000 anyway. Rows in my listview about 100 an more.

Upvotes: 1

Views: 1430

Answers (2)

Ralph Pina
Ralph Pina

Reputation: 761

I just encountered this issue. It appears there is a bug in AbsListView which prevents Android from drawing the views fast enough to honor the duration parameter: https://code.google.com/p/android/issues/detail?id=66744

Since smoothScrollToPositionFromTop works well when you are moving along a small number of views, we moved the ListView within x items of where we wanted to scroll, and then scrolled the last bit to simulate the motion.

So for example, we had a large list and we wanted to provide scroll to top on a button click. In the code below, we check how far down the list we are, and then adjust it up if needed. We then scroll the last bit.

if (listView != null && listView.getCount() > 0) {
    listView.post(new Runnable() {
        @Override
        public void run() {
            if (listView.getFirstVisiblePosition() > 20) {
                listView.setSelection(20);
            }
            listView.smoothScrollToPositionFromTop(0, 0, 300);
        }
    });
}

Upvotes: 1

ssantos
ssantos

Reputation: 16536

You may need to embed your call inside a Runnable.-

post(new Runnable() {
    @Override
    public void run() {
        listView.smoothScrollToPositionFromTop(position, listView.getHeight() - ROW_HEIGHT, 100);
    }
});

Upvotes: 1

Related Questions