问题描述
我已经在Recyclerview
中创建了活动Webview
内容.当我滚动Webview时,我想获得Y滚动位置.我尝试了Webview.getScrollY()
,Webview.getY()
,RecyclerView.getScrollY()
,RecyclerView.getY()
,...,但是效果不佳.我无法获得当前的滚动Y.有没有建议获取Webview
或RecyclerView
的滚动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
?
推荐答案
使用 RecyclerView.OnScrollListener 用于RecyclerView和用于网络视图的View.OnScrollChangeListener .
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!