diff --git a/cameraview/src/main/res/layout/surface_view.xml b/cameraview/src/main/res/layout/surface_view.xml
index 5c0c9dda..e5cdb74f 100644
--- a/cameraview/src/main/res/layout/surface_view.xml
+++ b/cameraview/src/main/res/layout/surface_view.xml
@@ -1,19 +1,17 @@
-
+
+
-
-
+ android:layout_height="match_parent" />
-
-
-
-
+
\ No newline at end of file
diff --git a/cameraview/src/main/res/layout/texture_view.xml b/cameraview/src/main/res/layout/texture_view.xml
index c4f6b0f1..a5c15ff2 100644
--- a/cameraview/src/main/res/layout/texture_view.xml
+++ b/cameraview/src/main/res/layout/texture_view.xml
@@ -1,11 +1,8 @@
-
-
-
-
-
+
\ No newline at end of file
diff --git a/cameraview/src/main/views/com/otaliastudios/cameraview/SurfaceCameraPreview.java b/cameraview/src/main/views/com/otaliastudios/cameraview/SurfaceCameraPreview.java
index ebbb05df..0abc3cdd 100644
--- a/cameraview/src/main/views/com/otaliastudios/cameraview/SurfaceCameraPreview.java
+++ b/cameraview/src/main/views/com/otaliastudios/cameraview/SurfaceCameraPreview.java
@@ -2,6 +2,7 @@ package com.otaliastudios.cameraview;
import android.content.Context;
import android.support.annotation.NonNull;
+import android.view.LayoutInflater;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
@@ -25,7 +26,8 @@ class SurfaceCameraPreview extends CameraPreview {
@NonNull
@Override
protected View onCreateView(Context context, ViewGroup parent) {
- final View root = View.inflate(context, R.layout.surface_view, parent); // MATCH_PARENT
+ View root = LayoutInflater.from(context).inflate(R.layout.surface_view, parent, false);
+ parent.addView(root, 0);
mSurfaceView = root.findViewById(R.id.surface_view);
final SurfaceHolder holder = mSurfaceView.getHolder();
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
diff --git a/cameraview/src/main/views/com/otaliastudios/cameraview/TextureCameraPreview.java b/cameraview/src/main/views/com/otaliastudios/cameraview/TextureCameraPreview.java
index 0e75b2c0..e2d34056 100644
--- a/cameraview/src/main/views/com/otaliastudios/cameraview/TextureCameraPreview.java
+++ b/cameraview/src/main/views/com/otaliastudios/cameraview/TextureCameraPreview.java
@@ -4,6 +4,7 @@ import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.SurfaceTexture;
import android.support.annotation.NonNull;
+import android.view.LayoutInflater;
import android.view.Surface;
import android.view.TextureView;
import android.view.View;
@@ -20,7 +21,8 @@ class TextureCameraPreview extends CameraPreview {
@NonNull
@Override
protected TextureView onCreateView(Context context, ViewGroup parent) {
- final View root = View.inflate(context, R.layout.texture_view, parent); // MATCH_PARENT
+ View root = LayoutInflater.from(context).inflate(R.layout.texture_view, parent, false);
+ parent.addView(root, 0);
TextureView texture = root.findViewById(R.id.texture_view);
texture.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {