diff --git a/camerakit/src/main/base/com/flurgle/camerakit/PreviewImpl.java b/camerakit/src/main/base/com/flurgle/camerakit/PreviewImpl.java index 789f04b6..6afcb182 100644 --- a/camerakit/src/main/base/com/flurgle/camerakit/PreviewImpl.java +++ b/camerakit/src/main/base/com/flurgle/camerakit/PreviewImpl.java @@ -61,28 +61,32 @@ abstract class PreviewImpl { return mHeight; } - void setTruePreviewSize(int width, int height) { + void setTruePreviewSize(final int width, final int height) { this.mTrueWidth = width; this.mTrueHeight = height; - - if (width != 0 && height != 0) { - AspectRatio aspectRatio = AspectRatio.of(width, height); - int targetHeight = (int) (getView().getWidth() * aspectRatio.toFloat()); - float scaleY; - if (getView().getHeight() > 0) { - scaleY = (float) targetHeight / (float) getView().getHeight(); - } else { - scaleY = 1; - } - - if (scaleY > 1) { - getView().setScaleX(1); - getView().setScaleY(scaleY); - } else { - getView().setScaleX(1 / scaleY); - getView().setScaleY(1); + getView().post(new Runnable() { + @Override + public void run() { + if (width != 0 && height != 0) { + AspectRatio aspectRatio = AspectRatio.of(width, height); + int targetHeight = (int) (getView().getWidth() * aspectRatio.toFloat()); + float scaleY; + if (getView().getHeight() > 0) { + scaleY = (float) targetHeight / (float) getView().getHeight(); + } else { + scaleY = 1; + } + + if (scaleY > 1) { + getView().setScaleX(1); + getView().setScaleY(scaleY); + } else { + getView().setScaleX(1 / scaleY); + getView().setScaleY(1); + } + } } - } + }); } int getTrueWidth() {