android加入摄像功能,Android调用前后摄像头同时工作

硬件环境:小米4

Android版本:6.0

咱们先看效果图:

Paste_Image.png

我把代码贴出来:

AndroidMainfest.xml文件(需要新增camera权限):

activity_main.xml文件:

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

tools:context="com.bihu.qdemopush.MainActivity">

android:layout_width="match_parent"

android:layout_height="200dp"

android:orientation="horizontal">

android:id="@+id/surfaceview1"

android:layout_width="0dp"

android:layout_weight="1"

android:layout_height="fill_parent" />

android:id="@+id/surfaceview2"

android:layout_width="0dp"

android:layout_weight="1"

android:layout_marginLeft="5dp"

android:layout_height="fill_parent" />

MainActivity.java文件:主要是对2个surfaceView的显示渲染

public class MainActivity extends AppCompatActivity {

SurfaceView surfaceview1, surfaceview2;

SurfaceHolder surfaceholder1, surfaceholder2;

String TAG = "MainActivity";

private Camera camera1 = null, camera2;

Camera.Parameters parameters;

@Override

你可能感兴趣的:(android加入摄像功能)