1
我有几个按钮的帧结构:的Android按钮后失踪添加内容视图
setContentView(R.layout.main_layout);
后,我把这个摄像头功能,
addContentView(mPreview, newFrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
它完全屏蔽我的XML布局。我想要在我的相机视图顶部的按钮,我该怎么做?
这是我的相机类:
import android.content.Context;
import android.hardware.Camera;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import java.io.IOException;
public class CameraSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
Camera mCamera;
boolean isPreviewRunning = false;
CameraSurfaceView(Context context) {
super(context);
SurfaceHolder mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void surfaceCreated(SurfaceHolder holder) {
synchronized(this) {
mCamera = Camera.open();
try {
mCamera.setPreviewDisplay(holder);
} catch (IOException e) {
Log.e("Camera", "mCamera.setPreviewDisplay(holder);");
}
mCamera.setDisplayOrientation(90);
mCamera.startPreview();
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
synchronized(this) {
try {
if (mCamera!=null) {
mCamera.stopPreview();
isPreviewRunning=false;
mCamera.release();
}
} catch (Exception e) {
Log.e("Camera", e.getMessage());
}
}
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
}
}
这是我的XML布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Background"
android:id="@+id/background"
android:onClick="background"
android:layout_gravity="left|bottom" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Camera"
android:id="@+id/camera"
android:onClick="camera"
android:layout_gravity="right|bottom" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save"
android:id="@+id/save"
android:onClick="save"
android:layout_gravity="center_horizontal|bottom" />
</FrameLayout>
的ID cameracontainer我应该在哪里放? –
在主要活动或相机类? –
在你的布局中使用xml,并将java代码放在'addcontentview'处的活动中 –