2014-02-25 36 views
0

一段時間後,我的頭從牆上撞過。基本上我的應用程序顯示了一個填充屏幕的相機預覽,當用戶點擊預覽時它會捕捉一個圖像(試圖通過透明的圖像按鈕來做到這一點)。在屏幕的底部,我想要另一個圖像按鈕,這次它會停止應用程序在做記錄。創建水龍頭捕捉透明的ImageButton通過CameraPreview

這裏是我的活動佈局

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <FrameLayout 
      android:id="@+id/camera_preview" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 
     </FrameLayout> 

     <ImageButton 
      android:id="@+id/button_capture" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@null" 
      android:contentDescription="@string/capture" 
      android:src="@null" /> 
    </FrameLayout> 

    <ImageButton 
     android:id="@+id/stopRecording" 
     android:layout_width="150dp" 
     android:layout_height="150dp" 
     android:layout_gravity="bottom|center" 
     android:layout_marginBottom="50dp" 
     android:background="@null" 
     android:contentDescription="@string/stopRec" 
     android:onClick="moveToUpload" 
     android:scaleType="fitCenter" 
     android:src="@drawable/rec_gray" /> 

</FrameLayout> 

我是想,因爲它們允許疊加使用FrameLayouts。

唯一的非多變的就是CameraPreview必須是一個FrameLayout。

任何幫助表示讚賞糾正這段代碼,

謝謝。

回答

1

如果你想添加按鈕在預覽使用單獨的佈局,併合並他們主版面

<merge xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 


    <include 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     layout="@layout/layout2" /> 

    <include 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     layout="@layout/layout1" /> 
</merge> 

一個佈局將僅包含預覽,第二個佈局將包含按鈕,合併後您將在預覽中放置按鈕。

如果你想使用透明按鈕,使用PNG文件與阿爾法香奈兒,這樣做的伎倆:)

+0

你是上帝。非常感謝你!!!!! – allyjweir

0

您需要添加Cameraview在這樣的XML這裏

<FrameLayout 
    android:id="@+id/mySurfaceView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <com.cam.CapturePreview 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    </com.cam.CapturePreview> 

    </FrameLayout> 

而且這將幫助你.. https://stackoverflow.com/a/7528543/472336

相關問題