1

I've got the following Kotlin code:

val scrollView = parent as? NestedScrollView
scrollView?.let {
    it.smoothScrollTo(0, 500)
}

The first time this code is called the scroll views scrollY is 0, and it successfully scrolls the view by 500 in the y. However, when this is called a second time it scrolls it another 500 (rather than scrolling it to 500 in the y, it will now be at 1000 and so on for consecutive calls.

Any idea what's going on here? When I drilled down into the code for NestedScrollView (and eventually down into OverScroller's startScroll method that is ultimately called I can see the distance parameter for that call on the y axis is 0 - as it should be for any other time than the first that my code is called).

EDIT: Important info - I tried with a ScrollView rather than a NestedScrollView and it worked as expected, however because my ScrollView needs to be inside a SwipeRefreshLayout I need it to be a NestedScrollView else pulling down always refreshes rather than scrolling.

Thomas Cook
  • 2,861
  • 1
  • 13
  • 33
  • I just had the same problem, in Kotlin as well, but do you think it is actually related to Kotlin? Wouldn't the same happen in Java? – arekolek Jan 12 '18 at 15:16

1 Answers1

1

The same happens in Java. This is a bug in Support Library since version 26.0.0, discussed here and on Google Issue Tracker.

gmk57
  • 539
  • 5
  • 15