嗨如何使此代码的作品?我想要这个类CameraSurfaceView放入一个相对的布局?Android布局:如何将此ViewGroup放入RelativeLayout中?
代码:
public class CameraSurfaceView extends ViewGroup implements SurfaceHolder.Callback{
private final String TAG = "Preview";
private SurfaceView mSurfaceView;
private SurfaceHolder mHolder;
private Size mPreviewSize;
private List<Size> mSupportedPreviewSizes;
private Camera mCamera;
public CameraSurfaceView(Context context) {
super(context);
mSurfaceView = new SurfaceView(context);
addView(mSurfaceView);
mHolder = mSurfaceView.getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
...
}
MainActivity;
public class MainActivity extends Activity{
RelativeLayout rlCamWrapper;
CameraSurfaceView cameraSurfaceView;
private SurfaceView surfaceView;
private boolean isRecording = false;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Hide the window title.
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
cameraSurfaceView = new CameraSurfaceView(this);
setContentView(R.layout.main);
}
...
}
XML:提前
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/relativeLayout1"
android:orientation="horizontal"
android:weightSum="1.0"
>
<VideoView
android:id="@+id/videoView1"
android:layout_alignParentTop="true"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:layout_weight=".5"/>
<RelativeLayout
android:id="@+id/surfaceViewWrapper"
android:layout_alignParentTop="true"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:layout_weight=".5">
<SurfaceView
android:id="@+id/surfaceView2"
android:layout_alignParentTop="true"
android:layout_height="fill_parent" android:layout_width="fill_parent"
/>
</RelativeLayout>
</LinearLayout>
感谢您的帮助球员。
你是什么意思@zrgiu? – jayellos 2012-03-13 03:26:21
抱歉,格式化错误。请检查编辑的回复 – zrgiu 2012-03-13 03:30:57
对不起@zrgiu,但我真的是新的android,我明白你的意思,但我不知道要编码。你能给我一些示例代码吗?这就是我在XML: –
jayellos
2012-03-13 03:37:04