I referenced Grafika CameraCaptureActivity for recording video while displaying a camera preview.
Changes made by me to the code (which is relevant), -
The user presses the button to start PreferencesActivity, selects the preferred camera resolution (which stores the values ββof widthand height) and presses the "Back" button to return to CameraCaptureActivity.
In the method openCamera. Instead of hard coding widthand heightI select values ββfromSharedPreferences
The attribute is AspectFrameLayout'sset this way android:background="@android:color/holo_blue_bright". Thus, the preview matches the sizeAspectFrameLayout
This problem occurs mainly when the size changes from a larger resolution to a smaller one.
On small screens (HTC One M7 / Xperia SP)

On large screens (Samsung Galaxy Tab S / Nexus 9) -

I noticed that this happens because it onSurfaceChangedis called twice. The first time with incorrect values ββfor widthand height, and the second time with the correct values.
However, the layout looks great if I leave the activity and return to it without making any changes. (Like going to PreferencesActivityand clicking "Back" without changing the resolution.)
I set the following to AndroidManifest.xml-
<activity android:name=".activity.camera.CameraCaptureActivity"
android:launchMode="singleInstance"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.Holo.Light.NoActionBar">
</activity>
EDIT: This problem only occurs when previewing. The recorded video is the correct size.
EDIT 2: This is my layout.xml
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/cameracapturescreen_rootparent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
tools:context="com.myapp.CameraCaptureActivity">
<com.myapp.activity.camera.PreviewFrameLayout
android:id="@+id/surfaceview_framelayout"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@android:color/holo_blue_bright"
android:layout_height="wrap_content">
<android.opengl.GLSurfaceView
android:id="@+id/cameraPreview_surfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="left"/>
</com.myapp.activity.camera.PreviewFrameLayout>
, , , , , . ( "" , CameraCaptureActivity.)