coding_android wrote:I have tried this tutorial and it works fine. What should I do to have a "capture" Button below the preview window. I know that it sets directly the content view at the moment . But how could I use that extend SurfaceView called Preview in my Style XML file in order to get the items like buttons or TextViews arranged with the surface view?
I'm really looking forward getting your answers.
Hi there,
I think I've found the solution to your question. I'm also a newbie

, so I'm not sure if this is the best solution, but it works for me.
The basic idea of my solution is to create a layout in xml which has in the bottom two buttons, a Capture and a Back button. Set this as the content view of your activity and after this add the mPreview on top of it with the addContentView() method.
The xml layout file for me looks something like this:
Using xml Syntax Highlighting
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
>
<Button
android:id="@+id/capture_button"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="Capture"
android:layout_weight="1"
/>
<Button
android:id="@+id/back_button"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="Back"
android:layout_weight="1"
/>
</LinearLayout>
</LinearLayout>
Parsed in 0.003 seconds, using
GeSHi 1.0.8.4
The activity should implement the OnClickListener interface in order to listen to button clicks.
The onCreate method will look something like this:
Using java Syntax Highlighting
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
mPreview = new Preview(this);
setContentView(R.layout.main);
addContentView(mPreview, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
((Button)findViewById(R.id.back_button)).setOnClickListener(this);
((Button)findViewById(R.id.capture_button)).setOnClickListener(this);
}
Parsed in 0.030 seconds, using
GeSHi 1.0.8.4
And finally in the onClick() method you do the saving or the exit from the program.
Using java Syntax Highlighting
public void onClick(View view) {
if (view == findViewById(R.id.back_button)) {
setResult(RESULT_OK);
finish();
}
else if (view == findViewById(R.id.capture_button)) {
mPreview.pause();
takePicture();
mPreview.resume();
}
}
Parsed in 0.030 seconds, using
GeSHi 1.0.8.4
Hope it helps.
Regards,
square