Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get scroll Y of RecyclerView or Webview

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 ?

like image 301
Phan Sinh Avatar asked Sep 08 '15 13:09

Phan Sinh


People also ask

Does RecyclerView have scroll?

To be able to scroll through a vertical list of items that is longer than the screen, you need to add a vertical scrollbar. Inside RecyclerView , add an android:scrollbars attribute set to vertical .


1 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;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ...

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

                mTotalScrolled += dy;

            }
        });

    ...

}

private int getScrollForRecycler(){
    return mTotalScrolled;
}
like image 132
JoeyJubb Avatar answered Oct 03 '22 04:10

JoeyJubb