开发者

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 hav开发者_运维百科e 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);?


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);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜