protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(new ScreenView(this));
var metrics = Resources.DisplayMetrics;
width = metrics.WidthPixels;
height = metrics.HeightPixels;
}
그런데 이런 방식으로 크기를 구해 대각선을 그어본 모습입니다.
보시다시피 원래 스크린 영역을 벗어나는 모습이군요. 아마도 위의 타이틀과 밑의 버튼들까지 포함하는 부분의 크기를 가져오는 듯 합니다.
그렇다면 순수하게 그림을 그릴 수 있는 부분만의 넓이는 어떻게 구할수 있을까요?
OnDraw로 들어오는 canvas에도 크기정보가 있습니다.
protected override void OnDraw(Canvas canvas)
{
int w = canvas.Width;
int h = canvas.Height;
MyClass.Inst.Initialize(new DeviceConnect(), 0, 0, w, h);
Paint pen = new Android.Graphics.Paint();
pen.Color = Android.Graphics.Color.Yellow;
canvas.DrawLine(0, 0, w, h, pen);
canvas.DrawLine(0, h, w, 0, pen);
}
이렇게 하면 다음과 같이 그려집니다.
다만 OnDraw에서 초기화를 하는 것이 합리적인지에 대한 의문점은 있지만, 아무튼 이런 방식이 있습니다.
혹시 자마린 폼이 아니라 그림이나 게임을 만든다면 이런 것도 필요하지 않을까 생각되는군요.


댓글 없음:
댓글 쓰기