Computer/Android
[Android] View 절대 좌표값
jamezc
2017. 2. 21. 21:15
View 절대 좌표값 구하는 방법
View.getLocatioinOnScreen(int[]);
위와 같은 함수를 사용하면 전체 스크린상의 절대 위치의 좌표를 구할수 있다.
예시로 아래와 같이 사용하면 된다.
public boolean chkTouchInside(View view, int x, int y) { int[] location = new int[2]; view.getLocationOnScreen(location); if (x >= location[0]) { if (x <= location[0] + view.getWidth()) { if (y >= location[1]) { if (y <= location[1] + view.getHeight()) { return true; } } } } return false; }