简体   繁体   English

获取recyclerview项目位置

[英]Get recyclerview item position

I have a layout, in which RecyclerView and a view is used.我有一个布局,其中使用了 RecyclerView 和一个视图。 View is overlapping the RecyclerView at centre.视图与中心的 RecyclerView 重叠。 I want to get the position of item at position of view when scroll or when recyclerview scroll stops.我想在滚动或 recyclerview 滚动停止时在视图位置获取项目的位置。

This is how you can get the item position.这是您获取项目位置的方法。

recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
    @Override
    public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
        super.onScrolled(recyclerView, dx, dy);
        int itemPoition = ((LinearLayoutManager) recyclerView.getLayoutManager()).findLastCompletelyVisibleItemPosition();
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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