2014-01-22 3 views
2

레이아웃에서 실제로 SurfaceView가 생성 될지 궁금합니다.프로그래밍 방식으로 레이아웃에서 생성 된 SurfaceView는 언제입니까?

이것은 Google Glass의 LiveCard 용 서비스에서 레이아웃을 생성하는 시나리오에 해당하므로 setContentView()를 사용하여이 레이아웃을 설정할 수있는 활동이 없습니다.

여전히 나는 서피스 뷰 SurfaceView 프로그래밍

을 만들어 얻을하는 것이 걸립니까 궁금해 나는 다음과 같은 레이아웃이 있습니다

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/black"> 

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

을하고 내가 가진 :

mLayout = (FrameLayout) inflater.inflate(R.layout.orientation_recorder, null); 
    mLayout.setWillNotDraw(false); 

    cameraView = (SurfaceView) mLayout.findViewById(R.id.camera_view); 
    cameraView.getHolder().addCallback(new SurfaceHolder.Callback() { 
      @Override 
      public void surfaceDestroyed(SurfaceHolder holder) { 
       Log.e("OR", "camera view sufrace destroyed"); 
      } 

      @Override 
      public void surfaceCreated(SurfaceHolder holder) { 
       Log.e("OR", "camera view sufrace created"); 
      } 

      @Override 
      public void surfaceChanged(SurfaceHolder holder, int format, int width, 
        int height) { 
       Log.e("OR", "camera view sufrace changed " 
         + " format: " + format 
         + " width: " + width 
         + " height: " + height); 
      } 
    }); 

하지만, SurfaceView를 생성 할 수 없습니다. 예를 들어 surfaceCreated()는 결코 위에서 호출되지 않습니다.

이렇게하려면 무엇이 필요합니까?

답변

2

당신은

setContentView(R.layout.main);<---- basically points to and uses your xml 

LinearLayout layout = (LinearLayout)findViewById(R.id.layout);<---- points to Layout defined in xml 

layout.addView(new SurfaceView(this));<----adds SurfaceView to layout 

당신이 할 수있는 레이아웃으로 컨텐츠보기를 설정하고 활동이나 주요 활동 클래스의 레이아웃에 표면보기를 추가하거나 당신이 전화의 주요 활동

view surface = new SurfaceView(this); 
SetContentView(surface); 
관련 문제