我有一个自定义的surfaceview,我需要添加到我当前的main.xml布局。此表面视图用于流式传输相机实时查看。我有问题做这项工作。在main.xml中显示自定义surfaceview
我没有问题,但是如果我运行代码为
cameraPreview = new HttpCameraPreview(this, null, viewWidth, viewHeight);
setContentView(cameraPreview);
,我不希望我的自定义surfaceview是主要的观点。我希望它是我的main.xml中的一个surfaceview。
希望得到一些建议/建议。我试图引用这个链接,但没有帮助。 Draw SurfaceView from layout xml
谢谢!
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/preview_image_view"
android:layout_height="wrap_content"
android:layout_weight="3.0"
android:layout_width="fill_parent"
/>
<SurfaceView Class ="org.saboteur.nikonshooter.HttpCameraPreview"
android:layout_width="fill_parent"
android:id="@+id/surface_preview"
android:layout_height="10dip"
android:layout_weight="3"/>
我的自定义surfaceview类部分代码如下所示::
public class HttpCameraPreview extends SurfaceView implements SurfaceHolder.Callback {
private static final String TAG = "test";
private static final String url = "http://bijint.com/jp/tokei_images/0022.jpg";
private CanvasThread canvasThread;
private SurfaceHolder holder;
private HttpCamera camera;
private HttpCameraPreview mSurfaceView;
private int viewWidth;
private int viewHeight;
public HttpCameraPreview(Context context, AttributeSet attributeSet, int viewWidth, int viewHeight) {
super(context, attributeSet);
Log.e("HttpCameraPreview", "inside HttpCameraPreview()");
Log.e("HttpCameraPreview", "create surface view to r.id");
try{
holder = getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_NORMAL);
this.viewWidth = viewWidth;
this.viewHeight = viewHeight;
canvasThread = new CanvasThread();
catch (Exception e){
Log.e("HttpCameraPreview", "--->Exception = "+e);
}
}
另一个问题:为什么 我无法使用
keithwb
2012-02-01 22:00:49