闲着无聊写的一个测试相机,查了各种资料希望对大家有帮助.
需要完整工程的可以到:https://git.oschina.net/mashuai1989/VideoTest.git下载
废话不多说了直接上代码
布局文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <SurfaceView android:id="@+id/surfaceview" android:layout_height="match_parent" android:layout_width="match_parent" /> <Button android:layout_alignParentBottom="true" android:text="@string/start" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/start"/> </RelativeLayout>
权限配置:
各种权限申请
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.videotest" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="20" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.videotest.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />