无法在recyclerView上获取nTh项目的CenterX和CenterY

时间:2018-02-08 16:14:30

标签: android

有没有办法在recyclerview上获取第三项的centerX和centerY

我用过

 public static Point getViewCenterCoordinatesOnScreen(View myView) {
        int[] location = new int[2];
        myView.getLocationInWindow(location);
        return new Point(location[0]/2, location[1]/2);
    }

并且它无法正常工作。

1 个答案:

答案 0 :(得分:0)

返回的位置是您要求的视图的0,0,它的中心不是位置除以2,正确:

public static Point getViewCenterCoordinatesOnScreen(View myView) {
    int[] location = new int[2];
    myView.getLocationInWindow(location);
    return new Point(location[0] + (myView.getWidth() / 2), location[1] + (myView.getHeight() / 2));
}