public int pointToPosition(int x, int y) {
Log.d("shit", "pointToPosition: x="+x+"y="+y);
Rect frame = new Rect();
final int childCount = this.getChildCount();
for (int i = 0; i < childCount; i++) {
View childView = this.getChildAt(i);
if (childView.getVisibility() == View.VISIBLE) {
childView.getHitRect(frame);
Log.d("shit", "pointToPosition: frame:"+frame);
}
if (frame.contains(x, y)) {
Log.d("shit", "pointToPosition: "+i);
return i;
}
}
return -1;
}
在viewgroup中获取触点的view