Using android.view.SurfaceView with a camera on part of the screen
Posted
by oneself
on Stack Overflow
See other posts from Stack Overflow
or by oneself
Published on 2010-03-20T23:04:31Z
Indexed on
2010/03/20
23:11 UTC
Read the original article
Hit count: 816
Hi,
I trying to put together an Android app that will take a picture and process it in some way. I'd like the layout to be similar to Google Goggles. Meaning, camera preview on the top, and some controls on the bottom using portrait orientation.
I've built a first version using code sample from here. This works, but I want to add a button on the bottom.
I've modified my main.xml to look as follows:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:stretchColumns="1">
<TableRow>
<android.view.SurfaceView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</TableRow>
<Button android:id="@+id/snap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Snap" />
<TableRow>
</TableRow>
</TableLayout>
But when I run this code I get an exception: java.lang.RuntimeException: startPreview failed.
When I replace the SurfaceView above with something else, e.g. a TextView, that it displays, but in landscape.
How can I get a camera preview on part of the screen using portrait view?
Thanks
© Stack Overflow or respective owner