2016-08-15 5 views
2

안드로이드 응용 프로그램을 실행하고 회전을 수정하자마자 회전하려고합니다. 나는 다음과 같은 방법을 시도했습니다 : Settings.System.ACCELEROMETER_ROTATION 회전하지 않습니다. ,하지만 그냥 회전 기능을 활성화, 당신의 도움이 필요합니다 (^ _ ^) 미리 감사드립니다. 당신은 단지 AndroidManifest를 당신의 활동이 속성을 추가 할 수 있습니다안드로이드 화면 회전, ACCELEROMETER_ROTATION

`

TableRow tableRow; 
Time HourProgram; 
RotateAnimation r; 
int H = 12000, M = 1200; 
int averageConsultationTime = 30; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.table); 
    setAutoOrientationEnabled(this, true); 

} 

public static void setAutoOrientationEnabled(Context context, 
     boolean enabled) { 
    Log.i("OK", "setAutoOrientationEnabledOK"); 
    Settings.System.putInt(context.getContentResolver(), 
      Settings.System.ACCELEROMETER_ROTATION, enabled ? 1 : 0); 
} 

public static boolean getRotationScreenFromSettingsIsEnabled(Context context) { 

    int result = 0; 
    try { 
     result = Settings.System.getInt(context.getContentResolver(), 
       Settings.System.ACCELEROMETER_ROTATION); 
    } catch (Settings.SettingNotFoundException e) { 
     e.printStackTrace(); 
    } 

    return result == 1; 
} 

`

+0

을 제공 [이] (http://stackoverflow.com/a/18268304/2900127)는 – 7geeky

+0

활동 당신, 그래서 안드로이드에서 기본적으로 회전하려고 기기에서 * 자동 회전 * 옵션을 사용하도록 설정해야합니다. –

답변

1

: 당신은 안드로이드 활동에 대한 자세한 정보를 찾을 수 있습니다

android:screenOrientation="landscape" 

여기 내 코드입니다 속성 here.

2

주요 활동에 onCreate이 코드를 추가

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); 
    } 
+0

감사합니다.이 방법으로도 작동합니다. –