简体   繁体   中英

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. 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 :)

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)

EDIT 2: i found this question, try reading it and probably you can solve the problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM