Android 相机在纵向模式下无法正常显示
我正在开发一个应用程序,其中我必须在纵向模式下录制视频。我正在使用此代码在纵向模式下录制视频 以下是我的主要功能Android 相机在纵向模式下无法正常显示,android,Android,我正在开发一个应用程序,其中我必须在纵向模式下录制视频。我正在使用此代码在纵向模式下录制视频 以下是我的主要功能 SurfaceView srfRecord = (SurfaceView) findViewById(R.id.surfaceRecord); surfaceHolder = srfRecord.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TY
SurfaceView srfRecord = (SurfaceView) findViewById(R.id.surfaceRecord);
surfaceHolder = srfRecord.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_NORMAL);
public void startRecording(int Request) {
try {
srfRecord.setBackgroundColor(Color.TRANSPARENT);
requestcode = Request;
sdCardRecordingPath = Environment.getExternalStorageDirectory()
+ "/" + Request + "_Video.mp4";
mediaRecorder = new MediaRecorder();
mCamera.unlock();
mediaRecorder.setCamera(mCamera);
mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setProfile(CamcorderProfile
.get(CamcorderProfile.QUALITY_HIGH));
mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
mediaRecorder.setOutputFile(sdCardRecordingPath);
mediaRecorder.setMaxDuration(10000);
mediaRecorder.prepare();
mediaRecorder.start();
mediaRecorder.setOnInfoListener(this);
mediaRecorder.setOnErrorListener(this);
recording = true;
} catch (Exception e) {
String message = e.getMessage();
Log.i(null, "Problem Start" + message);
mediaRecorder.release();
}
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
mCamera = Camera.open();
if (mCamera != null) {
//mCamera.setDisplayOrientation(90);
Parameters params = mCamera.getParameters();
params.set("orientation", "portrait");
mCamera.setDisplayOrientation(90);
//params.setPreviewSize(screenWidth, screenHeight-180);
mCamera.setParameters(params);
} else {
Toast.makeText(getApplicationContext(), "Camera not available!",
Toast.LENGTH_LONG).show();
}
}
public void stopRecording() {
if (mediaRecorder != null) {
mediaRecorder.setOnInfoListener(null);
mediaRecorder.setOnErrorListener(null);
mediaRecorder.stop();
mediaRecorder.release();
mCamera.stopPreview();
mediaRecorder = null;
recording = false;
}
}
布局
它正在工作,但处于纵向模式
surfaceview未显示全宽,但仅显示宽度的1/4部分,其他3/4部分显示为黑色
请给我这个问题的解决方案
谢谢要么放下
setType()
要么使用SURFACE\u TYPE\u PUSH\u BUFFERS
。另外,使用层次结构查看器或uiautomatorviewer
确认您的SurfaceView
填充了您期望的区域。除此之外,你们可以试试我的相机库,看看你们是否能得到更好的结果:嗨,commansWare,我已经检查过了,我的版面有问题,如果把surfaceview只放在framelayout中,然后它就会填满整个版面,但如果我要用任何其他的线性版面,它只占用1/4的空间,我正在发布我的版面
<LinearLayout
android:id="@+id/lnrTop"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:baselineAligned="false"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/lnrPick1"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/custom_backgroud"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:id="@+id/lnrPick2"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginLeft="3dp"
android:layout_weight="1"
android:background="@drawable/custom_backgroud"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:id="@+id/lnrPick3"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginLeft="3dp"
android:layout_weight="1"
android:background="@drawable/custom_backgroud"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:id="@+id/lnrPick4"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginLeft="3dp"
android:layout_weight="1"
android:background="@drawable/custom_backgroud"
android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/frmView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/lnrBottom"
android:layout_below="@+id/lnrTop"
android:background="@drawable/custom_backgroud" >
<SurfaceView
android:id="@+id/surfaceRecord"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible" />
<!-- <TextView -->
<!-- android:id="@+id/txtTimer" -->
<!-- android:layout_width="wrap_content" -->
<!-- android:layout_height="wrap_content" -->
<!-- android:text="10:00" -->
<!-- android:textSize="18sp" -->
<!-- android:textColor="#ffffff"/> -->
<VideoView
android:id="@+id/videoview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone"
>
</VideoView>
<Chronometer
android:id="@+id/txtTimer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:format="@string/chronometer_initial_format"
android:textColor="#ffffff"
android:textSize="19sp"
android:textStyle="normal"
android:typeface="sans" />
</FrameLayout>
<RelativeLayout
android:id="@+id/lnrBottom"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="@drawable/custom_backgroud" >
<Button
android:id="@+id/btnSettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="@android:drawable/ic_media_play" />
<Button
android:id="@+id/btnPlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@android:drawable/ic_media_play" />
<Button
android:id="@+id/btnRefresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="@android:drawable/ic_media_play" />
</RelativeLayout>