ScrollTo always works, smoothScrollTo only sometimes

I have subclassed HorizontalScrollView so that I have some kind of custom scroll behavior, but found that smoothScrollTo doesn't always work. I had to get around this problem using the following code:

smoothScrollTo(x, y); scrollTo(x, y); 

This ensures that the scroll is actually executed, even if the smoothScrollTo function does not work, since scrollTo works every time. Why is this happening? How can I get smoothScrollTo to work every time?

+4
source share
2 answers

try the following:

 mScrollView.post(new Runnable() { @Override public void run() { mScrollView.smoothScrollTo(x, y); } }); 
+4
source

The following code will work:

  final int scrollposition = Math.round(hr/24.0f * 1440f); final ScrollView sv = (ScrollView)findViewById(R.id.graphScrollView); //sv.smoothScrollTo(0, scrollposition); sv.post(new Runnable() { @Override public void run() { sv.smoothScrollTo(0, scrollposition); } }); 

Reason: It will wait for the scroll to be sent before the base code runs.

0
source

Source: https://habr.com/ru/post/1501065/


All Articles