protected override void OnLayout(bool changed, int l, int t, int r, int b) { base.OnLayout(changed, l, t, r, b); if (!changed) { return; } var msw = MeasureSpec.MakeMeasureSpec(r - l, MeasureSpecMode.Exactly); var msh = MeasureSpec.MakeMeasureSpec(b - t, MeasureSpecMode.Exactly); mainLayout.Measure(msw, msh); mainLayout.Layout(0, 0, r - l, b - t); var metrics = Resources.DisplayMetrics; liveView.SetX(0); liveView.SetY(0); imageView.SetX(half_width); imageView.SetY(0); exitButton.SetX(half_width); exitButton.SetY(metrics.HeightPixels - 200); }
private void SetOrientation() { var metrics = new DisplayMetrics(); Display.GetMetrics(metrics); var moduleWidth = _cameraModule.Width * metrics.Density; var moduleHeight = _cameraModule.Height * metrics.Density; var parameters = _camera.GetParameters(); double proportionalPreviewHeight; switch (Display.Rotation) { case SurfaceOrientation.Rotation0: _cameraModule.IsViewInverted = false; _cameraModule.IsPortrait = true; proportionalPreviewHeight = _previewSize.Width * moduleWidth / _previewSize.Height; _camera.SetDisplayOrientation(90); parameters.SetRotation(90); break; case SurfaceOrientation.Rotation180: _cameraModule.IsViewInverted = true; _cameraModule.IsPortrait = true; proportionalPreviewHeight = _previewSize.Width * moduleWidth / _previewSize.Height; _camera.SetDisplayOrientation(270); parameters.SetRotation(270); break; case SurfaceOrientation.Rotation90: _cameraModule.IsViewInverted = false; _cameraModule.IsPortrait = false; proportionalPreviewHeight = _previewSize.Height * moduleWidth / _previewSize.Width; _camera.SetDisplayOrientation(0); parameters.SetRotation(0); break; default: _cameraModule.IsPortrait = false; _cameraModule.IsViewInverted = true; proportionalPreviewHeight = _previewSize.Height * moduleWidth / _previewSize.Width; _camera.SetDisplayOrientation(180); parameters.SetRotation(180); break; } _camera.SetParameters(parameters); var verticalOffset = (moduleHeight - proportionalPreviewHeight) / 2f; _textureView.SetX(0); _textureView.SetY((float)verticalOffset); _cameraModule.PreviewBottomY = _cameraModule.Height - verticalOffset / 2; _textureView.LayoutParameters = new FrameLayout.LayoutParams((int)Math.Round(moduleWidth), (int)Math.Round(proportionalPreviewHeight)); }