get scroll Y of RecyclerView or Webview

后端 未结 2 1107
独厮守ぢ
独厮守ぢ 2020-12-31 10:42

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.

相关标签:
2条回答
  • 2020-12-31 11:12

    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;
    }
    
    0 讨论(0)
  • 2020-12-31 11:16

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

    mTotalScrolled  = recyclerView.computeVerticalScrollOffset();
    
    0 讨论(0)
提交回复
热议问题