2011-03-14 47 views
2

我想開發具有3個標籤的應用程序,從而使第一選項卡,相機和拍攝圖像。到目前爲止,我有兩個相機問題:激活相機標籤(Android)內

  1. 我希望相機鎖定在縱向或橫向模式。如果我將照相機鎖定在肖像上,那麼圖像似乎旋轉了,並且我幾乎用camera.parameters嘗試了所有內容,但無法修復它。如果我將相機鎖定在橫向模式,那麼問題在於選項卡菜單也會將方向改爲橫向。是否有方法只在該選項卡內更改方向,並將標籤菜單保留爲縱向模式?

  2. 圖像以某種方式被拉伸。我猜想問題在於相機使用全屏幕的高度和寬度,但是我的應用程序試圖將相機預覽放在比屏幕更小的框架佈局內,這是因爲選項卡菜單,所以圖像被拉伸。有沒有辦法解決這個問題,並顯示實際的相機預覽與標籤菜單上呢?

我使用1個活性創建該3個標籤,並使用此佈局:

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="5dp"> 
    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:padding="5dp" 
     android:layout_weight="1"/> 
    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0"/> 
    </LinearLayout> 
</TabHost> 

我使用1個活性爲每個標籤。專門針對第一選項卡(照相機)我使用preview.class在以下佈置:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/layout" android:orientation="vertical" android:layout_height="wrap_content" android:layout_width="wrap_content"> 
<FrameLayout android:layout_weight="1" android:id="@+id/preview" android:layout_gravity="fill_vertical" android:fitsSystemWindows="true" android:layout_height="wrap_content" android:layout_width="wrap_content"> 
</FrameLayout> 
<Button android:text="Click" android:id="@+id/buttonClick" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center"></Button> 
</LinearLayout> 

回答

0

我與3個標籤,其中所述第一接線片必須處於縱向模式的相機預覽無失真做到了。 嗯,這可能與3個技巧:)

首先設置你的子預覽活動與肖像模式強制選項卡是縱向。 無論是在的onCreate()

this.getParent().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 

或在清單

android:screenOrientation="portrait" 

使用然後轉動你不應該使用參數的屏幕,因爲它不工作,但(僅適用於自2.2)

if (Build.VERSION.SDK_INT >= 8) camera.setDisplayOrientation(90); 

最後以避免strectch你可以,但在FameLayout在全屏模式下,使之去的壓片(標籤是像一個覆蓋,但攝像頭下方是不變形全屏)

<TabWidget 
android:id="@android:id/tabs" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_alignParentTop="true"/> 
<FrameLayout 
android:id="@android:id/tabcontent" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_below="@android:id/tabs"/> 

等瞧!