Programmatically scroll to the top of a NestedScrollView

后端 未结 13 1662
情书的邮戳
情书的邮戳 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:36

    I also faced similar kind scenario. In my case when I scroll down to end, FAB button should be appears and when user tap on that FAB button should go to the top of the page. For that I added @SilentKnight answer NestedScrollView.scrollTo(0, 0); For go to the top but which is not enough for smooth animation for scroll up.
    For smooth animation I have used @Sharj answer which is NestedScrollView.fullScroll(View.FOCUS_UP); But then my AppBar is not visible there fore I have to expanded the AppBar as following appBarLayout1.setExpanded(true). So using these three I can able smoothly go to top of the page.

    nestedScrollView.fullScroll(View.FOCUS_UP);
    nestedScrollView.scrollTo(0,0);
    appBarLayout1.setExpanded(true);
    

提交回复
热议问题