Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android smoothScrollBy behaving badly

I have a ListView that I am calling smoothScrollBy() on. 95% of the time, the smoothScrollTo() behaves as intended. However there are times that it does not end up in the intended spot! I have verified that I am giving it the same value. I notice that the smooth scrolling is not so smooth when the errors are made, however there are no other tasks that my application is performing that I would have control over.

I am not quite sure what is going on in the background but a likely culprit is garbage collection.

95% accuracy is not good enough in this situation. I am going to have to implement some sort of a correction mechanism to make sure the ListView lands on the correct spot in these instances.

Is there a better way to use smoothScrollBy() other than simply calling view.smoothScrollBy(distance, time);?

like image 302
tyler Avatar asked Sep 29 '11 16:09

tyler


2 Answers

sometimes it will be because of the timing issue. When the views are added to your listview and the time you do

view.smoothScrollBy(distance, time);

the listview or the ui still need not get refreshed. So do this in the views post thread with a specific delay. Eg.

view.postDelayed(new Runnable{
    view.smoothScrollBy(distance, time);
},1000);
like image 53
Arun Avatar answered Oct 24 '22 04:10

Arun


Try some of these:

Listview has its own scrolling mechanism. It scrolls when the content is added.

  1. Assign listview height (android:layout_height) to match_parent or fill_parent.

  2. If your assigning a adapter in a working thread. Do not perform any UI actions in the thread.

If these do not solve the issue. Please post the code where you assign the adapter to the list view if any. Or the relevant code.

Also the xml layout code.

Hope this helps.

like image 6
mipreamble Avatar answered Oct 24 '22 05:10

mipreamble