[英]How to get current scrollbar position in RecyclerView?
I need to get current position of scrollbar on screen. 我需要获取屏幕上滚动条的当前位置。 I supposed that getVerticalScrolbarPosition would do the trick, but for some reason it gives me only zeroes.
我以为getVerticalScrolbarPosition可以解决问题,但是由于某种原因,它只给我零。 Here is the code I use:
这是我使用的代码:
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
(...)
getRecyclerView().setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int srollBarPosition = getRecyclerView().getVerticalScrollbarPosition();
}
});
What I am doing wrong? 我做错了什么?
Try using getScrollY(), here is the documentation :) 尝试使用getScrollY(), 这里是文档:)
EDIT: hm, if for you can work anyway getFirstVisiblePosition()
gives you not the y scrolls but the index of the first visible item of the list(might be the same, depending on what you need to do) 编辑:嗯,如果您仍然可以工作,
getFirstVisiblePosition()
不会给您y滚动,而是为列表中第一个可见项的索引(可能相同,这取决于您需要执行的操作)
EDIT 2: i found this question, try reading it and probably you can solve the problem 编辑2:我发现了这个问题,请尝试阅读它,也许您可以解决问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.