i have a custom surfaceview which i need to add into my current main.xml layout. this surfaceview is used to stream camera liveview. i having issues making this work.
i have no issue if i run the code as
cameraPreview = new HttpCameraPreview(this, null, viewWidth, viewHeight);
setContentView(cameraPreview);
however, i do not want my custom surfaceview to be the main view. i want it to be a surfaceview inside my main.xml.
hope to get some suggestions/advises. i tried refering to this link, but no help too. Draw SurfaceView from layout xml
thanks!
part of the main.xml as below:
<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"/>
my custom surfaceview class partial code look like this:
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);
}
}