您的位置:首页 > 移动开发 > Android开发

android-->>>mediarecorder的使用

2012-08-26 19:29 357 查看
最近研究一下怎么使用android录像功能,在网上找的例子无尽的报错,脑袋都大了,还好现在一个一个解决了...........。

遇到了N多个问题,开始时start failed,后来又stop failed,整理在这供自己以后学习参考,如果大家有更好的方法-->>回帖告诉俄这个菜鸟哦....

先给个图吧,测试时在模拟器上测试的.......,在真机上测试有效(2.3.3系统)

(添加--->>>添加摄像预览及双击屏幕拉近镜头功能.......,还有待其他功能的实现)真机测试不同的型号可能问题,有待解决........

(修改--->>修改第一次播放完回来在缩放的时候报错.....(解决))

(添加长按拉远焦距)修改使用seekbar缩放镜头,对于start failed错误一般是摄像大小有问题(本类在华为c8812上测试无压力,使用的是480p拍摄,720p报错),还有就是上次使用了摄像头但是没有释放资源导致错误(一定要记得释放,要不然在真机上系统摄像头都会报错的......)。记得别忘了加权限..........

效果图如下:


中间是个抽屉可以选择不同的拍摄场景,右边拖动条负责缩放焦距

主要代码如下:
package com.zte.camera;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import com.zte.camera.MySeekBar.OnSeekBarChangeListener;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.AutoFocusCallback;
import android.hardware.Camera.OnZoomChangeListener;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.Size;
import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.StatFs;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.SlidingDrawer;
import android.widget.SlidingDrawer.OnDrawerScrollListener;
import android.widget.Toast;

/**
 * (Fail to connect to camera service)这个错误,是因为上次使用Camera后没有释放 (satrt
 * failed||stop failed)是因为2.3.*的模拟器不支持MediaRecorder的编码格式,使用真机k
 */
public class Camera_test extends Activity implements Callback,
		AutoFocusCallback {
	private Button m_click_button;
	private Button m_Noclick_button;
	private MediaRecorder mMediaRecorder;
	private SurfaceView mPreview;
	protected static Camera mCamera;
	private SurfaceHolder holder;
	private boolean mButtonClickState = true;
	public static final int MEDIA_TYPE_VIDEO = 2;
	public static final int MEDIA_TYPE_AUDIO = 1;
	private Handler mHandlerExit;
	private int mExit = 1;
	private boolean mFlag_Null = false;
	private boolean isRecording = false;
	protected static int mValues = 0;
	// private boolean mFlagCamera_Lock = false;
	protected static Context mContext;
	protected static int openAll = 0;
	protected static int openChange_open = 1;
	protected static int openChange_para = 2;
	private static Camera.Parameters params;
	private int mPictures_High;
	private int mPictures_Width;
	protected static int mZoomMax;// 缩放最大值
	protected static boolean mVedio_Flag = false;
	private GestureDetector mGestureDetector;
	private SlidingDrawer mSlidingDrawer;
	private MySeekBar mySeekBar;
	private RelativeLayout mSeekbar_RelativeLayout;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		mContext = this;
		init();
		handler_Exit();
	}

	/**
	 * 获取手机支持的最大录取高,宽
	 * 
	 * @param c
	 */
	private void pictureHW(Camera c) {
		Parameters parameters = c.getParameters();
		List<Size> supportedPreviewSizes = parameters
				.getSupportedPreviewSizes();
		mPictures_Width = supportedPreviewSizes.get(0).width;// 获取最大录像的高宽
		mPictures_High = supportedPreviewSizes.get(0).height;
		Toast.makeText(Camera_test.this,
				mPictures_Width + "----" + mPictures_High, Toast.LENGTH_SHORT)
				.show();
	}

	/**
	 * 用于没有摄像头时退出
	 */
	private void handler_Exit() {
		mHandlerExit = new Handler() {
			@Override
			public void handleMessage(Message msg) {

				int what = msg.what;
				if (what == mExit) {
					System.exit(0);
				}
				super.handleMessage(msg);
			}
		};
	}

	/**
	 * 退出时的对话框
	 */
	private void camera_Null() {
		AlertDialog.Builder dialog = new AlertDialog.Builder(this);
		dialog.setMessage("没有可用的摄像头,请更改设备....");
		dialog.setNegativeButton("确定", new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				Message msg = new Message();
				msg = Message.obtain(mHandlerExit, mExit);
				mHandlerExit.sendMessage(msg);

			}
		});
		dialog.show();

	}

	/**
	 * 初始化
	 */
	public void init() {
		m_click_button = (Button) findViewById(R.id.layout_button_click);
		m_Noclick_button = (Button) findViewById(R.id.layout_button_no_click);
		button_Click_State(mButtonClickState);
		mPreview = (SurfaceView) findViewById(R.id.layout_surfeve);
		mSlidingDrawer = (SlidingDrawer) findViewById(R.id.drawer_layout);
		mySeekBar = (MySeekBar) findViewById(R.id.seekbar);
		mySeekBar.setProgress(0);
		mSeekbar_RelativeLayout = (RelativeLayout) findViewById(R.id.seekbar_layout);
		seekbar_Listener();
		slidingDrawerWidget();
		slidingDrawerClickListener();
		mGestureDetector = new GestureDetector(this,
				new GestureDetectorListener());
		holder = mPreview.getHolder();
		holder.addCallback(this);
		holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);// 这句话很重要,不加的话,模拟器直接报错,真机直接黑屏(经过测试的哦)
		buttonClickListener();
		getSdcardSize();
	}

	private void seekbar_Listener() {
		mySeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

			@Override
			public void onStopTrackingTouch(MySeekBar VerticalSeekBar) {
				params.setZoom(mySeekBar.getProgress());
				mCamera.setParameters(params);
				try {
					mCamera.startSmoothZoom(mValues);
				} catch (Exception e) {

				}
			}

			@Override
			public void onStartTrackingTouch(MySeekBar VerticalSeekBar) {
				params.setZoom(mySeekBar.getProgress());
				mCamera.setParameters(params);
				try {
					mCamera.startSmoothZoom(mValues);
				} catch (Exception e) {

				}
			}

			@Override
			public void onProgressChanged(MySeekBar VerticalSeekBar,
					int progress, boolean fromUser) {
				if (mySeekBar.getProgress() <= mZoomMax) {
					params.setZoom(mySeekBar.getProgress());
					mCamera.setParameters(params);
					try {
						mCamera.startSmoothZoom(mValues);
					} catch (Exception e) {

					}
				}
			}
		});
	}

	private ImageView mImageView1;
	private ImageView mImageView2;
	private ImageView mImageView3;
	private ImageView mImageView4;
	private ImageView mImageView5;
	private ImageView mImageview_handler;

	public void slidingDrawerWidget() {
		mImageView1 = (ImageView) findViewById(R.id.lineralayout_content_imageview1);
		mImageView2 = (ImageView) findViewById(R.id.lineralayout_content_imageview2);
		mImageView3 = (ImageView) findViewById(R.id.lineralayout_content_imageview3);
		mImageView4 = (ImageView) findViewById(R.id.lineralayout_content_imageview4);
		mImageView5 = (ImageView) findViewById(R.id.lineralayout_content_imageview5);
		mImageview_handler = (ImageView) findViewById(R.id.imageview_handler);
		mImageview_handler.setBackgroundResource(R.drawable.icon_arrow_up);
	}

	private boolean flag;

	public void slidingDrawerClickListener() {
		mSlidingDrawer.setOnDrawerScrollListener(new OnDrawerScrollListener() {

			@Override
			public void onScrollStarted() {
				if (mSlidingDrawer.isOpened()) {
					mImageview_handler
							.setBackgroundResource(R.drawable.icon_arrow_down_selected1);
					flag = true;
				} else {
					mImageview_handler
							.setBackgroundResource(R.drawable.icon_arrow_up_selected);
					flag = false;
				}
			}

			@Override
			public void onScrollEnded() {
				if (flag) {
					mImageview_handler
							.setBackgroundResource(R.drawable.icon_arrow_up);
				} else {
					mImageview_handler
							.setBackgroundResource(R.drawable.icon_arrow_down);
				}
			}
		});
		mImageView1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Log.i("RG", "mImageView1");
				if (colorEffects != null) {
					params.setColorEffect(colorEffects.get(0));
					mCamera.setParameters(params);
				}

			}
		});
		mImageView2.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Log.i("RG", "mImageView2");
				if (colorEffects != null) {
					params.setColorEffect(colorEffects.get(1));
					mCamera.setParameters(params);
				}
			}
		});
		mImageView3.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Log.i("RG", "mImageView3");
				if (colorEffects != null) {
					params.setColorEffect(colorEffects.get(4));

					mCamera.setParameters(params);
				}
			}
		});
		mImageView4.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Log.i("RG", "mImageView4");
				if (colorEffects != null) {
					params.setColorEffect(colorEffects.get(3));
					mCamera.setParameters(params);
				}
			}
		});
		mImageView5.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Log.i("RG", "mImageView5");
				if (colorEffects != null) {
					params.setColorEffect(colorEffects.get(2));
					mCamera.setParameters(params);
				}
			}
		});
	}

	List<String> colorEffects;

	public void ImageViewBackGround() {
		colorEffects = mCamera.getParameters().getSupportedColorEffects();
		if (colorEffects == null) {
			return;
		}
		Toast.makeText(Camera_test.this,
				"您的手机支持" + colorEffects.size() + "种拍摄场景", Toast.LENGTH_SHORT)
				.show();
	}

	/**
	 * button的状态改变
	 * 
	 * @param flag
	 */
	public void button_Click_State(boolean flag) {
		if (flag) {
			m_click_button.setEnabled(true);
			m_Noclick_button.setEnabled(false);
		} else {
			m_click_button.setEnabled(false);
			m_Noclick_button.setEnabled(true);
		}
	}

	/**
	 * button监听
	 */
	public void buttonClickListener() {
		m_click_button.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (prepareVideoRecorder()) {
					try {
						mMediaRecorder.start();
					} catch (Exception e) {
						Toast.makeText(Camera_test.this, "start Camera error",
								Toast.LENGTH_SHORT).show();
					}

					isRecording = true;
					mButtonClickState = false;
					mVedio_Flag = true;
					button_Click_State(mButtonClickState);
				} else {
					mButtonClickState = true;
					mVedio_Flag = false;
					releaseCamera();
				}
			}
		});
		m_Noclick_button.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (isRecording) {
					mButtonClickState = true;
					mVedio_Flag = false;
					// releaseCamera();
					releaseMediaRecorder();
					isRecording = false;
					mValues = 0;
					// mCamera.lock();
					params.setZoom(mValues);
					mCamera.setParameters(params);
					try {
						mCamera.startSmoothZoom(mValues);
					} catch (Exception e) {
						Toast.makeText(mContext, "startSmoothZoom--stop",
								Toast.LENGTH_SHORT).show();
					}
					mySeekBar.setProgress(mValues);
					// openCamera(openAll);
				}
			}
		});
	}

	/**
	 * open camera and set camera parameters
	 * 
	 * @param openFlag
	 * @return
	 */
	@SuppressLint("NewApi")
	private boolean openCamera(int openFlag) {

		if (openFlag == openAll) {
			if (mCamera == null) {
				try {
					mCamera = Camera.open(0);
					System.out.println(mCamera);
				} catch (Exception e) {
					System.out.println("error---");
					mFlag_Null = true;
					e.printStackTrace();
					return false;
				}
				try {
					System.out.println("Camera_test.openCamera()");
					mCamera.setPreviewDisplay(holder);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			params = mCamera.getParameters();
			params.setRotation(90);
			params.setPictureFormat(PixelFormat.JPEG);
			mCamera.setDisplayOrientation(90);
			mCamera.setParameters(params);
			mCamera.startPreview(); // 开启预览
		} else if (openFlag == openChange_open) {
			if (mCamera == null) {
				try {
					mCamera = Camera.open(0);
				} catch (Exception e) {
					mFlag_Null = true;
					return false;
				}

				try {
					mCamera.setPreviewDisplay(holder);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		} else if (openFlag == openChange_para) {
			params = mCamera.getParameters();
			params.setPictureFormat(PixelFormat.JPEG);
			mZoomMax = params.getMaxZoom();
			mySeekBar.setMax(mZoomMax);
			params.setZoom(mValues);
			mCamera.setDisplayOrientation(90);
			ImageViewBackGround();
			mCamera.setParameters(params);
			mCamera.startPreview(); // 开启预览
			mCamera.autoFocus(null);
			mCamera.setZoomChangeListener(new ZoomGestureListener());

		} else {
			return false;
		}

		pictureHW(mCamera);
		return true;
	}

	/**
	 * 设置MediaRcorder
	 * 
	 * @return
	 */
	private boolean prepareVideoRecorder() {
		// releaseCamera();
		if (mMediaRecorder == null) {
			mMediaRecorder = new MediaRecorder();
		}
		mCamera.unlock();
		mMediaRecorder.setCamera(mCamera);
		mMediaRecorder.setPreviewDisplay(holder.getSurface());// 设置预览
		mMediaRecorder.reset();
		mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);// 录音
		mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);// 视频
		// mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);//
		// 3gp格式
		// mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);//
		// 音频编码格斯
		// mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);//
		// 视频编码格式
		mMediaRecorder.setProfile(CamcorderProfile
				.get(CamcorderProfile.QUALITY_480P));
		mMediaRecorder.setAudioChannels(2);
		mMediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO)// 存储路径
				.toString());
		mMediaRecorder.setMaxFileSize(getSdcardSize());// 获取存储最大值
		// mMediaRecorder.setVideoSize(480, 320);// 录屏分辨率
		// mMediaRecorder.setVideoFrameRate(24);// 没秒的帧数

		try {
			mMediaRecorder.prepare();
		} catch (IllegalStateException e) {
			releaseMediaRecorder();
			return false;
		} catch (IOException e) {
			releaseMediaRecorder();
			return false;
		}
		return true;
	}

	/**
	 * 释放mMediaRecorder资源,并改变button状态
	 */
	private void releaseMediaRecorder() {
		if (mMediaRecorder != null) {
			mMediaRecorder.stop();
			mMediaRecorder.reset();
			mMediaRecorder.release();
			mMediaRecorder = null;
		}
		button_Click_State(mButtonClickState);
	}

	/**
	 * 获取存储路径
	 * 
	 * @param type
	 * @return
	 */
	private static File getOutputMediaFile(int type) {
		File mediaStorageDir = new File(
				Environment
						.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
				"MyCameraApp");
		if (!mediaStorageDir.exists()) {
			if (!mediaStorageDir.mkdirs()) {
				return null;
			}
		}
		String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
				.format(new Date());
		File mediaFile = null;
		if (type == MEDIA_TYPE_VIDEO) {
			mediaFile = new File(mediaStorageDir.getPath() + File.separator
					+ "VID_" + timeStamp + ".3gp");
		} else if (type == MEDIA_TYPE_AUDIO) {
			mediaFile = new File(mediaStorageDir.getPath() + File.separator
					+ "");
		} else {

		}
		return mediaFile;

	}

	protected void onPause() {
		super.onPause();
		releaseMediaRecorder();// 如果正在使用MediaRecorder,首先需要释放它。
	}

	/**
	 * 释放Camera资源
	 */
	private void releaseCamera() {
		if (mCamera != null) {
			mCamera.stopPreview();
			mCamera.release();
			// mCamera.lock();
			mCamera = null;
		}

	}

	@Override
	protected void onDestroy() {

		releaseMediaRecorder();
		releaseCamera();
		super.onDestroy();
	}

	/**
	 * 获取sdcard剩下可用的资源,返回long型,因为setMaxFileSize方法是long类型
	 * 
	 * @return
	 */
	public long getSdcardSize() {
		long availableSpare = 0;
		if (android.os.Environment.getExternalStorageState().equals(
				android.os.Environment.MEDIA_MOUNTED)) {
			String sdcard = Environment.getExternalStorageDirectory().getPath();
			StatFs statFs = new StatFs(sdcard);
			long blockSize = statFs.getBlockSize();
			long blocks = statFs.getAvailableBlocks();
			availableSpare = blocks * blockSize;
		} else {
			return 0;
		}
		return availableSpare;
	}

	@Override
	public void surfaceChanged(SurfaceHolder holder, int format, int width,
			int height) {
		Log.i("RG", "surfaceChanged----->>>>");
		if (mFlag_Null) {
			camera_Null();
		} else {
			openCamera(openChange_para);
			Log.i("RG", "mCamera--->>>" + mCamera);
		}

	}

	@Override
	public void surfaceCreated(SurfaceHolder holder) {
		Log.i("RG", "surfaceCreated----->>>>");
		openCamera(openChange_open);

	}

	@Override
	public void surfaceDestroyed(SurfaceHolder holder) {
		Log.i("RG", "surfaceDestroyed----->>>>");
		if (mCamera != null) {
			releaseCamera();
		}
		if (mMediaRecorder != null) {
			releaseMediaRecorder();
		}

	}

	/**
	 * 自动回掉
	 */
	@Override
	public void onAutoFocus(boolean success, Camera camera) {
		Log.i("RG", "onAutoFocus====");
		openCamera(openChange_para);
		mCamera.takePicture(null, null, pictureCallBack);
	}

	/**
	 * 
	 */
	PictureCallback pictureCallBack = new PictureCallback() {
		@Override
		public void onPictureTaken(byte[] data, Camera camera) {
			// TODO Auto-generated method stub
			try {
				Bitmap bm = BitmapFactory.decodeByteArray(data, 0, data.length);
				File file = new File(getOutputMediaFile(MEDIA_TYPE_AUDIO)
						.toString());
				BufferedOutputStream bos = new BufferedOutputStream(
						new FileOutputStream(file));
				bm.compress(Bitmap.CompressFormat.JPEG, 100, bos);
				bos.flush();
				bos.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	};

	public static void initializeZoom() {
		if (!params.isZoomSupported()) {
			Toast.makeText(mContext, "不支持缩放功能", Toast.LENGTH_SHORT).show();
		} else {
			Toast.makeText(mContext, "支持缩放功能", Toast.LENGTH_SHORT).show();
			Toast.makeText(mContext, mZoomMax + "最大值", Toast.LENGTH_SHORT)
					.show();
			mValues += 5;
			params.setZoom(mValues);
			try {
				mCamera.setParameters(params);
			} catch (Exception e) {
				Toast.makeText(mContext, "setParameters", Toast.LENGTH_SHORT)
						.show();
			}
		}
	}
	@Override
	public boolean dispatchTouchEvent(MotionEvent ev) {
		int y = (int) ev.getY();
		if (y < 10) {
			System.out.println("y < 200");
			return mGestureDetector.onTouchEvent(ev);
		}
		return super.dispatchTouchEvent(ev);
	}

	private boolean seekBar_Flag = true;

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		int ev = event.getAction();
		switch (ev) {
		case MotionEvent.ACTION_DOWN:
			if (seekBar_Flag) {
				mSeekbar_RelativeLayout.setVisibility(View.VISIBLE);
				seekBar_Flag = !seekBar_Flag;
			} else {
				mSeekbar_RelativeLayout.setVisibility(View.GONE);
				seekBar_Flag = !seekBar_Flag;
			}

		}
		return super.onTouchEvent(event);
	}
}

/**
 * 缩放回监听
 * 
 * @author root
 * 
 */
class ZoomGestureListener implements OnZoomChangeListener {

	@Override
	public void onZoomChange(int zoomValue, boolean stopped, Camera camera) {
		if (zoomValue == 60) {
			System.out.println("zoomValue == 3");
			Camera_test.mCamera.stopSmoothZoom();
		}
	}
}

/**
 * 双击屏幕监听
 * 
 * @author root
 * 
 */
class GestureDetectorListener extends SimpleOnGestureListener {

	@Override
	public boolean onDoubleTap(MotionEvent e) {
		Log.i("onDoubleTap", "onDoubleTap----");
		if (!Camera_test.mVedio_Flag
				&& Camera_test.mValues < Camera_test.mZoomMax) {
			Camera_test.initializeZoom();
			try {
				Camera_test.mCamera.startSmoothZoom(Camera_test.mValues);
			} catch (Exception ew) {
				Toast.makeText(Camera_test.mContext, "startSmoothZoom",
						Toast.LENGTH_SHORT).show();

			}
		} else {
			Toast.makeText(Camera_test.mContext, "录像时不能缩放", Toast.LENGTH_SHORT)
					.show();
		}
		return super.onDoubleTap(e);
	}
}



main.xnl布局如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff" >

    <SurfaceView
        android:id="@+id/layout_surfeve"
        android:layout_width="fill_parent"
        android:layout_height="440dip" >
    </SurfaceView>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        android:layout_below="@id/layout_surfeve" >

        <Button
            android:id="@+id/layout_button_click"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/button_click_state"
            android:text="start record" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="50dip"
            android:layout_weight="2" >
        </LinearLayout>

        <Button
            android:id="@+id/layout_button_no_click"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/button_click_state"
            android:text="stop record" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center" >

        <include layout="@layout/drawer_item" />
    </LinearLayout>

    <RelativeLayout
        android:id="@+id/seekbar_layout"
        android:layout_width="45dip"
        android:layout_height="350dip"
        android:layout_alignParentRight="true"
        android:layout_marginTop="35dip"
        android:orientation="horizontal"
        android:visibility="gone" >

        <com.zte.camera.MySeekBar
            android:id="@+id/seekbar"
            android:layout_width="16dip"
            android:layout_height="350dip"
            android:layout_centerInParent="true"
            android:progressDrawable="@drawable/progress"
            android:thumb="@drawable/thumb"
            android:thumbOffset="0dip" />
    </RelativeLayout>

</RelativeLayout>


drawer_item.xml布局如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <SlidingDrawer
        android:id="@+id/drawer_layout"
        android:layout_width="50dip"
        android:layout_height="wrap_content"
        android:background="#00ffffff"
        android:content="@+id/lineralayout_content"
        android:handle="@+id/imageview_handler" >

        <LinearLayout
            android:id="@+id/lineralayout_content"
            android:layout_width="50dip"
            android:layout_height="200dip"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/lineralayout_content_imageview1"
                android:layout_width="50dip"
                android:layout_height="50dip"
                android:background="@drawable/normal" />

            <LinearLayout
                android:layout_width="50dip"
                android:layout_height="15dip" >
            </LinearLayout>

            <ImageView
                android:id="@+id/lineralayout_content_imageview2"
                android:layout_width="50dip"
                android:layout_height="50dip"
                android:background="@drawable/heipai" />

            <LinearLayout
                android:layout_width="50dip"
                android:layout_height="15dip" >
            </LinearLayout>

            <ImageView
                android:id="@+id/lineralayout_content_imageview3"
                android:layout_width="50dip"
                android:layout_height="50dip"
                android:background="@drawable/landi" />

            <LinearLayout
                android:layout_width="50dip"
                android:layout_height="15dip" >
            </LinearLayout>

            <ImageView
                android:id="@+id/lineralayout_content_imageview4"
                android:layout_width="50dip"
                android:layout_height="50dip"
                android:background="@drawable/huangdi" />

            <LinearLayout
                android:layout_width="50dip"
                android:layout_height="15dip" >
            </LinearLayout>

            <ImageView
                android:id="@+id/lineralayout_content_imageview5"
                android:layout_width="50dip"
                android:layout_height="50dip"
                android:background="@drawable/dise" />
        </LinearLayout>

        <ImageView
            android:id="@+id/imageview_handler"
            android:layout_width="50dip"
            android:layout_height="50dip" />
    </SlidingDrawer>

</LinearLayout>


别忘了加权限哦.............

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.zte.camera"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <application
        android:icon="@drawable/application_login"
        android:label="@string/app_name" >
        <activity
            android:name=".Camera_test"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.RECORD_VIDEO" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
</manifest>






                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: