RecycleView 的 PointToPosition 替代方案

PointToPosition Alternative for RecycleView

我正在替换 ListView by the RecyclerView, but I'm using a pointToPosition 方法,是否有等效方法?


对于 RecyclerView,您有 findChildViewUnder (float x, float y)。 此方法 returns 一个子视图,然后您可以使用它来使用 getChildAdapterPosition(View child).

检索适配器位置

这将使您获得父 RecyclerView 中 (x, y) 处的视图:

View targetView = recyclerView.findChildViewUnder(x, y);

这会为您提供项目在当前由该视图表示的基础数据集中的位置:

recyclerView.getChildAdapterPosition(targetView);