2016-11-25 1 views
0

검색을 시도했지만이 문제에 대한 해결책을 찾지 못했습니다. 고정 된 가로 방향의 카메라 응용 프로그램이 있습니다. orientationEventListener는 모든 내 버튼을 제대로 회전시킵니다. 그러나 대화 상자 나 경고 대화 상자가 표시되고 이러한 대화 상자는 회전되지 않는 버튼이 있습니다. 여기 고정 장치 방향 이외의 Dialog 및 AlertDialog 회전

button1.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      final Dialog dialog = new Dialog(CameraActivity.this); 
      dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); 
      dialog.setContentView(R.layout.layout_dialog_mode); 
      // set up texts in layout_dialog_mode 

private void createMenu() { 
    AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    final String[] modeS = {getString(R.string.mode_1), getString(R.string.mode_2), getString(R.string.mode_3), getString(R.string.mode_4), getString(R.string.mode_5)}; 
    builder.setTitle(getString(R.string.mode_title)); 
    builder.setSingleChoiceItems(modeS, mode, new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int item) { 
      // set things as chosen by user 
      } 
      dialog.dismiss(); /* close menu after selection */ 
     } 
    }); 

    builder.show(); 
} 

layout_dialog_mode MainActivity

에 해당 단축 코드 TextViews 및 ImageViews 함유의 LinearLayout이다.

버튼의 회전은 다음과 같이 작동

private void initialiseOEListener() { 

    oEListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) { 
     @Override 
     public void onOrientationChanged(int orientation) { 
      try { 
       if (orientation == ORIENTATION_UNKNOWN) return; 

       orientation = (orientation + 45)/90 * 90; 

       switch (orientation) { 
        // set params and orientation 
       } 

       ImageButton ibu = (ImageButton) findViewById(R.id.button0); 
       ibu.setRotation(orientation); 
       ibu = (ImageButton) findViewById(R.id.button1); 
       ibu.setRotation(orientation); 
       // and so on 

      } catch (Exception e) { 


      } 
     } 
    }; 

이제 내 질문 : 그것은 버튼과 같은 방식으로 대화 상자를 회전 할 수 있습니까? 현재이 활동의 ​​기기 방향을 가로로 설정 했으므로 순간적으로 가로로 표시됩니다. 예를 들어 사용자가 전화기를 세로로 회전하고 button1을 클릭하면 대화 상자가 회전되지 않으므로 잘못 표시됩니다.

많은 감사

답변

0

좋아요. 그래서 각 대화 상자에 대해 별도의 활동을 생성하여 문제를 해결했습니다. 이제 문제는 새로운 전경 대화 상자 작업이 회전 할 때 백그라운드 작업이 함께 회전합니다! 전경 액티비티를 회전 할 때 배경 액티비티 방향을 어떻게 든 설정할 수 있습니까?