본문 바로가기

Android

[android]view 절대좌표 구하기


public void getAbsCoord(int resId) {
View v = findViewById(resId);
if (v == null)
throw new IllegalArgumentException("this is not a view");
Rect r = new Rect();
v.getGlobalVisibleRect(r); //RootView 레이아웃을 기준으로한 좌표.
//custom Log
Log.l(v.getResources().getResourceName(resId).split(":")[1]
+ " 의절대좌표::", r.left, r.top, r.right, r.bottom);
}
//to use _ view가 생성된 이후에 실행
getAbsCoord(R.id.resId);