2017-02-18 5 views
2

다시 도움이 필요합니다. 내 카메라 활동 (조각)이 내 탐색 창과 겹치는 것 같습니다. 이 문제를 해결하는 방법을 모르겠습니다. 카메라가 탐색 창을 겹치고 있습니다 - Android

는 나의 것 같습니다 방법 :

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_first_fragment" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.dcar.FirstFragment"> 
<!-- 
<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_second_fragment" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.dcar.MainActivity" 
    > 
--> 
    <FrameLayout 
     android:id="@+id/camera_view" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     > 

    </FrameLayout> 
<!-- 
</FrameLayout> 
--> 
</RelativeLayout> 
: 이것은 내 activity_camera.xml입니다

public class CameraFragment extends Fragment { 

    private Camera mCamera = null; 
    private CameraView mCameraView = null; 


    View v; 

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


     try { 
      mCamera = Camera.open();//you can use open(int) to use different cameras 
     } catch (Exception e) { 
      Log.d("ERROR", "Failed to get camera: " + e.getMessage()); 
     } 

     if (mCamera != null) { 
      mCameraView = new CameraView(getActivity(), mCamera);//create a SurfaceView to show camera data 
      FrameLayout camera_view = (FrameLayout) v.findViewById(R.id.camera_view); 
      camera_view.addView(mCameraView);//add the SurfaceView to the layout 
      // camera_view.onCreate(savedInstanceState); 
     } 
     //-------------------------------------------------------------------------------camera 

     return v; 
    } 

    private class CameraView extends SurfaceView implements SurfaceHolder.Callback { 

     private SurfaceHolder mHolder; 
     private Camera mCamera; 

     public CameraView(Context context, Camera camera) { 
      super(context); 
      mCamera = camera; 
      mCamera.setDisplayOrientation(90); 
      //get the holder and set this class as the callback, so we can get camera data here 
      mHolder = getHolder(); 
      mHolder.addCallback(this); 
      mHolder.setType(SurfaceHolder.SURFACE_TYPE_NORMAL); 
     } 

     @Override 
     public void surfaceCreated(SurfaceHolder surfaceHolder) { 
      try{ 
       //when the surface is created, we can set the camera to draw images in this surfaceholder 
       mCamera.setPreviewDisplay(surfaceHolder); 
       mCamera.startPreview(); 
      } catch (IOException e) { 
       Log.d("ERROR", "Camera error on surfaceCreated " + e.getMessage()); 
      } 
     } 

     @Override 
     public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) { 
      //before changing the application orientation, you need to stop the preview, rotate and then start it again 
      if(mHolder.getSurface() == null)//check if the surface is ready to receive camera data 
       return; 

      try{ 
       mCamera.stopPreview(); 
      } catch (Exception e){ 
       //this will happen when you are trying the camera if it's not running 
      } 

      //now, recreate the camera preview 
      try{ 
       mCamera.setPreviewDisplay(mHolder); 
       mCamera.startPreview(); 
      } catch (IOException e) { 
       Log.d("ERROR", "Camera error on surfaceChanged " + e.getMessage()); 
      } 
     } 

     @Override 
     public void surfaceDestroyed(SurfaceHolder surfaceHolder) { 
      //our app has only one screen, so we'll destroy the camera in the surface 
      //if you are using with more screens, please move this code your activity 
      mCamera.stopPreview(); 
      mCamera.release(); 
     } 
     } 
    } 

:

Click Here

이것은 CameraFragment.java 내 코드입니다

MainActivity.java :

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 


     DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
       this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
     drawer.setDrawerListener(toggle); 
     toggle.syncState(); 



    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 
      navigationView.setNavigationItemSelectedListener(this); 

Fragment home = new FirstFragment(); 
     FragmentManager FM = getFragmentManager(); 
     FM 
       .beginTransaction() 
       .replace(R.id.content_frame, home) 


        .commit(); 
} 

@Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 
     android.app.FragmentManager fragmentManager = getFragmentManager(); 

     if (id == R.id.action_ar) { 
      fragmentManager.beginTransaction() 
        .replace(R.id.content_frame, new CameraFragment()) 
        .commit(); 
     } 
     else if (id == R.id.action_map) { 
      fragmentManager.beginTransaction() 
        .replace(R.id.content_frame, new SecondFragment()) 
        .commit(); 

     } 
     else if (id == R.id.action_direction) { 

      fragmentManager.beginTransaction() 
        .replace(R.id.content_frame, new ThirdFragment()) 
        .commit(); 

     } 

내 activity_main.xml :

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

    <include 
     layout="@layout/app_bar_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true" 
     app:headerLayout="@layout/nav_header_main" 
     app:menu="@menu/activity_main_drawer" /> 

</android.support.v4.widget.DrawerLayout> 
+0

어떤 탐색 창을? 레이아웃에서 서랍을 만들지는 않았지만, 보통 "서랍"이라는 의미로 사용했습니다. –

+0

나는 가지고있다. 하지만 여기에 붙여 넣지 않았습니다. "여기를 클릭하십시오"에서 볼 수 있듯이, 네비게이션 서랍 (파란색)이라는 이름을 붙여 식별 할 수 있습니다. – Problematic

+0

서랍에 문제가있는 경우 서랍이 어떻게 구현되는지 확인해야합니다. 이미지만으로는 충분하지 않습니다. 'Activity'에서 발생한'Fragment' 트랜잭션도 포함시켜야합니다. –

답변

0

나는 동일한 문제가 있었다. 이 작품은 나를위한

drawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() { 
    @Override 
    public void onDrawerSlide(View drawerView, float slideOffset) { 
     drawerLayout.bringChildToFront(drawerView); 
     drawerLayout.requestLayout(); 
    } 
    ... 
}