2014-02-11 2 views
0

카메라 미리보기에서 아래 그림과 같은 오버레이를 구현하고 싶습니다. 이 같은 Picture with camera overlay in android camera previewAndroid 카메라 미리보기에 오버레이가 있음

내 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을 사용하지 않고 그냥 프로그래밍하는 솔루션을 발견했습니다.이 방법이 유용 할 수 있습니다.

카메라 클래스가 Fragment를 확장합니다. 버튼이 생성 된 다음보기에 추가 된 것을 볼 수 있습니다. 카메라 표면보기 후에

@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

내가 개발 한 App에서도 동일한 문제가있었습니다. 카메라 미리보기에서 버튼이 필요했습니다. 내가 한 모든 당신이 원하는보기 항목에서 XML 레이아웃에 - 단지 속성 0.5 50 % 투명

행운

입니다

android:alpha"0.5" 

를 추가

관련 문제