Home » Android » android – get scroll Y of RecyclerView or Webview

android – get scroll Y of RecyclerView or Webview

Posted by: admin May 14, 2020 Leave a comment


I have created a activity Webview content placed in Recyclerview.
I want to get the scroll Y position when I scroll webview.
I tried Webview.getScrollY(), Webview.getY(), RecyclerView.getScrollY(), RecyclerView.getY(),… but it do not work fine. I can’t get current scroll Y.
Is there any suggest for get scroll Y of Webview or RecyclerView ?

How to&Answers:

Use a RecyclerView.OnScrollListener for the RecyclerView and a View.OnScrollChangeListener for the webview.

You’ll have to keep track of the total scroll yourself, like this:

private int mTotalScrolled = 0;

protected void onCreate(Bundle savedInstanceState) {


    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);

                mTotalScrolled += dy;




private int getScrollForRecycler(){
    return mTotalScrolled;


computeVerticalScrollOffset()is more convenient at this situation as @Pkmmte mentioned.

mTotalScrolled  = recyclerView.computeVerticalScrollOffset();