tags:

views:

28

answers:

2

I need to have a video preview(on a Surface) and a TextView and a few buttons(at the bottom of the screen)

Currently, my preview's height is large but it's narrow and at the far left at the screen and the TextView is not visible.

The buttons are placed at the bottom as I require.

How do I make the preview's width large as well and the TextView visible?

Here is my layout:

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView  
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="Android Recorder"
/>
<SurfaceView android:id="@+id/camsurface"       
 android:layout_width="fill_parent" 
 android:layout_height="0px"
 android:layout_weight="1" />

 <TextView  
 android:id="@+id/recording_time"
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text=" 00:00"
/>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>

<Button android:id="@+id/btn_settings" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="Settings"/>

 <Button android:id="@+id/btn_record" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="Record" /> 

+1  A: 

Your "preview is very small" is very small because you have it set for 140px square, hard-wired in your layout.

Either take advantage of android:layout_weight with LinearLayout, or use RelativeLayout, to make your SurfaceView take as much space as is available.

For example, here is a layout with a Button at the bottom and a WebView filling up all remaining space:

<?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"
    >
    <WebView android:id="@+id/webkit"
        android:layout_width="fill_parent" 
        android:layout_height="0px"
        android:layout_weight="1"
    />
    <Button android:id="@+id/helpcast"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="View Helpcast"
    />
</LinearLayout>
CommonsWare
thank you. Could you please explain the weight attribute. I didn't understand how the documentation had explained it.
Namratha
I set the height and weight attribute of the Surface View as you said but please see above for the problem.
Namratha
problem is solved but do explain the weight attribute
Namratha
A: 

Corrected :

 <?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"

Namratha