Programmatically scroll to the top of a NestedScrollView

后端 未结 13 1658
情书的邮戳
情书的邮戳 2020-12-13 12:02

Is there a way to programmatically scroll to the top of a NestedScrollView by also triggering the scroll events for the parent? smoothScrollTo(x, y)

13条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 12:28

    Some time NestedScrollView.scrollTo(0, 0); and scrollview.pageScroll(View.FOCUS_UP); does not work

    At that you need to use fling() and smoothScrollTo() together

    SAMPLE CODE

    nestedScrollView.post {
       nestedScrollView.fling(0)
       nestedScrollView.smoothScrollTo(0, 0)
    }
    

提交回复
热议问题