2014-02-11 39 views
0

我想在相機預覽中實現如下圖所示的覆蓋圖。 Picture with camera overlay in android camera preview在Android Camera Preview中重疊覆蓋

我的XML是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:baselineAligned="false" 
android:orientation="horizontal" > 
<FrameLayout 
    android:id="@+id/camera_preview" 
    android:layout_width="match_parent" 
    android:layout_height="399dp" > 
</FrameLayout> 
<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/camera_preview" 
    android:layout_marginLeft="35dp" 
    android:text="@string/share" /> 
<Button 
    android:id="@+id/button_capture" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@+id/button1" 
    android:layout_alignParentRight="true" 
    android:layout_alignTop="@+id/button1" 
    android:layout_marginRight="38dp" 
    android:text="@string/capture" /> 
    </RelativeLayout> 

如果我嘗試使用列表視圖的FrameLayout它不執行我的代碼後表現出來攝像頭預覽。任何想法如何可以在相機預覽中有這樣的覆蓋?

回答

0

我在我的應用程序的相機預覽之上添加了一個按鈕。我發現這個解決方案完全避免使用XML,而只是將其編程。這可能對您有用。

相機類擴展片段。但你可以在這裏看到按鈕被創建並添加到視圖中。在相機表面視圖之後。

@Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     View rootView = inflater.inflate(R.layout.camera_fragment, 
       container, false); 

     myCamera = getCameraInstance(); 

     recording = false; 

     if (myCamera == null) { 
      Toast.makeText(getActivity(), "Fail to get Camera", 
        Toast.LENGTH_LONG).show(); 
     } 

     Button button = new Button(getActivity()); 

     //button.setBackgroundResource(R.drawable.record); 

     RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
       LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
     params.addRule(RelativeLayout.CENTER_HORIZONTAL); 
     params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
     params.width = 260; 
     params.height = 260; 
     button.setLayoutParams(params); 
     button.setText("Record"); 

     myCameraSurfaceView = new GetCamera(getActivity(), myCamera); 

     ((ViewGroup) rootView).addView(myCameraSurfaceView); 
     ((ViewGroup) rootView).addView(button); 
     button.setOnClickListener(this); 

     return rootView; 
    } 
0

我和我開發的應用程序有同樣的問題。我需要預覽相機上的按鈕。 我所做的是在XML佈局,在任何你想要查看項目 - 只需添加屬性

android:alpha"0.5" 

其中0.5是50%透明

好運