获取RecyclerView或Webview的滚动Y [英] get scroll Y of RecyclerView or Webview

查看:169
本文介绍了获取RecyclerView或Webview的滚动Y的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Recyclerview中创建了活动Webview内容. 当我滚动Webview时,我想获得Y滚动位置. 我尝试了Webview.getScrollY()Webview.getY()RecyclerView.getScrollY()RecyclerView.getY(),...,但是效果不佳.我无法获得当前的滚动Y. 有没有建议获取WebviewRecyclerView的滚动Y?

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 ?

推荐答案

使用

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

这篇关于获取RecyclerView或Webview的滚动Y的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆