Programmatically scroll to the top of a NestedScrollView

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

    Nothing worked for me, and I don't really know why this worked, but here is my solution and problem.

    When adding recycler view to a nested scroll view, it showed recycler view on screen when getting to that activity. In order to scroll all the way up, I had to use this:

    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.details_recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    ProductDescriptionAdapter adapter = new ProductDescriptionAdapter(this);
    adapter.setData(mProduct.getDetails());
    recyclerView.setAdapter(adapter);
    NestedScrollView scrollView = (NestedScrollView) findViewById(R.id.scroll);
    scrollView.getParent().requestChildFocus(scrollView, scrollView);
    

提交回复
热议问题