반응형
getLocationOnScreen / getLocationInWindow의 잘못된 좌표
호출 getLocationOnScreen()
또는 getLocationInWindow()
둘 다 나에게 top/Y
약 30px (상태 / 알림 표시 줄의 높이)가 너무 아래에 있는 좌표를 제공 합니다. left/X
좌표에 죽었어요.
위에서 언급했듯이 차이점은 상태 / 알림 표시 줄 때문이라고 생각합니다. 내가 틀릴 수 있습니다. 알림 바의 크기를 알 수 있으면 해결할 수있을 것 같은데, 문제가 있습니다.
어떤 도움이라도 대단히 감사하겠습니다.
상태 / 알림 표시 줄의 높이를 다음과 같이 결정하여이 문제를 해결했습니다.
View globalView = ...; // the main view of my activity/application
DisplayMetrics dm = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dm);
int topOffset = dm.heightPixels - globalView.getMeasuredHeight();
View tempView = ...; // the view you'd like to locate
int[] loc = new int[2];
tempView.getLocationOnScreen(loc);
final int y = loc[1] - topOffset;
상태 표시 줄 높이를 가져오고 오프셋을 조정하는 방법은 다음과 같습니다.
final int[] location = new int[2];
anchor.getLocationInWindow(location); // Includes offset from status bar, *dumb*
Rect anchorRect = new Rect(location[0], location[1],
location[0] + anchor.getWidth(), location[1] + anchor.getHeight());
anchor.getRootView().findViewById(android.R.id.content).getLocationInWindow(location);
int windowTopOffset = location[1];
anchorRect.offset(0, -windowTopOffset);
같은 문제가 있습니다.
offset = myView.GetOffsetY();
그 값으로 Y 좌표를 조정하십시오.
coordY -= offset;
``-method를 제공하는 클래스 :
class MyView extends View {
public int GetOffsetY() {
int mOffset[] = new int[2];
getLocationOnScreen( mOffset );
return mOffset[1];
}
}
이 답변은 상태 표시 줄의 높이를 얻는 방법이 포함되어 있지 않지만,의 행동을 설명 않습니다 getLocationOnScreen()
와 getLocationInWindow()
같은 값을 반환.
일반 활동 (대화가 아님)의 경우이 두 가지 방법이 동일한 값을 반환 할 것으로 예상해야합니다. 창은 상태 표시 줄 아래에 배치되므로 (y 좌표가 아닌 z 순서로) 이러한 방법을 사용하여 상태 표시 줄의 높이를 결정할 수 없습니다.
반응형
'UFO ET IT' 카테고리의 다른 글
Java에서 호출되는 오버로드 된 메서드 (0) | 2020.12.25 |
---|---|
클래스 파일 이름의 $ 1은 무엇입니까? (0) | 2020.12.25 |
필드와 관련된 조건을 기반으로 데이터 프레임의 하위 집합 추출 (0) | 2020.12.25 |
ASP.NET MVC 개발을위한 Windows Azure 또는 Amazon EC2? (0) | 2020.12.25 |
CQRS 예제 및 스크린 캐스트 (0) | 2020.12.25 |