2011-08-04 63 views
0

我有一個活動在landscape mode中設置,並且必須保持這種方式(所以作爲我的問題的答案不要告訴我在PORTRAIT mode原因中設置我的活動這不是一個解決方案)。在橫向模式下設置一個按鈕的問題

而且我想提出一個按鈕在屏幕的像這樣的底部:

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

但我可以做我的it.All嘗試讓我只有這個:

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

這是我的xml文件:

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

不要忘記我的活動是在LANDSCAPE模式。 謝謝!

+0

我感到困惑。您有隻在橫向模式下顯示的活動?或者是什麼 ? –

+0

我的活動在LANDSCAPE模式下設置,我想在屏幕底部設置一個按鈕(不在活動的底部) – adrian

回答

1

訣竅是使用layout_weight完成的,它告訴佈局使用所有可用空間。因此,您要創建兩個佈局,第二個佈局具有固定的高度,並告訴第一個使用所有可用空間。這種解決方案將適用於橫向和縱向模式。

<?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> 
+0

SurfaceView會放在Firsat LinearLayout上? – adrian

+0

不工作-http://i56.tinypic.com/14aai39.png請幫助meee – adrian

+0

你出錯了。看起來你正在展示的圖片是在風景中,但你正在旋轉90度觀看。 –

2

使用圖像按鈕來代替。

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