0

I have an activity which is set up in the landscape mode and must remain this way(!So as an answer to my question don't tell me to set my activity in the PORTRAIT mode cause this is not a solution).

And I wanna put a button at the bottom of the screen like this:

http://i52.tinypic.com/30n9o5t.png

but I just can do it.All my attempts got me only this:

http://i53.tinypic.com/54acjs.png

Here is my xml file:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    >
<SurfaceView  
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
   android:id="@+id/surface_camera"
    />
<Button android:id="@+id/btnPhoto" 
android:layout_gravity="right" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="Take Photo !!"></Button>
</FrameLayout>

Don't forget my activity is in LANDSCAPE mode. Thank you!

adrian
  • 4,574
  • 17
  • 68
  • 119
  • I got confused. You have an activity which is displayed ONLY in landscape mode ? Or what ? – Mojo Risin Aug 04 '11 at 12:34
  • My activity is set in LANDSCAPE mode and I wanna set one button at the bottom of the screen(not at the bottom of the activity) – adrian Aug 04 '11 at 12:44

2 Answers2

2

Using Image button instead.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    >
<SurfaceView  
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
   android:id="@+id/surface_camera"
    />
<ImageButton android:id="@+id/btnPhoto" 
    android:layout_gravity="right" 
    android:layout_width="your_button_width" 
    android:layout_height="your_button_height" 
    android:background="@drawable/your_button_here">
</ImageButton>
</FrameLayout>
Anonymous
  • 21
  • 2
1

The trick is done using layout_weight which is telling the layout to use all free space available. So you are creating two layouts the second with fixed height and the tell the first to use all the free space. This solution will work in both cases Landscape and Portrait mode.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
    <LinearLayout android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:orientation="vertical"
    android:layout_weight="1.0">
    </LinearLayout>
    <LinearLayout android:layout_width="fill_parent"
    android:layout_height="40dp">
    <!-- place your buttons in this layout -->
    </LinearLayout>
</LinearLayout>

UPDATE

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal">
    <LinearLayout android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:orientation="vertical"
    android:layout_weight="1.0">
    </LinearLayout>
    <LinearLayout android:layout_width="40dp"
    android:layout_height="fill_parent"></LinearLayout>
</LinearLayout>
Mojo Risin
  • 8,136
  • 5
  • 45
  • 58
  • And SurfaceView would be put on the firsat LinearLayout? – adrian Aug 04 '11 at 13:08
  • You are getting something wrong. It seems the picture you're showing is in landscape but you're viewing in rotated on 90 degrees. – Mojo Risin Aug 04 '11 at 13:24
  • No, the trick is that when I'm using the android camera the preview is rotated with 90 degrees.To fix that I set up my activity in LANDSCAPE mode.That's all.And what I wanna do next is to put a button at the bottom of the screen that's all:)...But I just can't get this to work! – adrian Aug 04 '11 at 13:28
  • Actually you want to set in at the bottom but on the right sight which is the botton from your view point :). Check the update – Mojo Risin Aug 04 '11 at 13:38
  • Is great, but still one more problem...The writing on the button is astray.Do you know how could I fix that? http://i51.tinypic.com/2u4oaww.png – adrian Aug 04 '11 at 13:49
  • There is no build in method for that. You'll have to override a view and in onDraw method to rotate the canvas manually. Here is good post about it - http://stackoverflow.com/questions/1258275/vertical-rotated-label-in-android – Mojo Risin Aug 04 '11 at 13:55
  • @george let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/2129/discussion-between-mojo-risin-and-george) – Mojo Risin Aug 04 '11 at 13:56