2016-07-14 66 views

回答

0

您可以設置屏幕方向。

Button button = (Button) findViewById(R.id.button); 
button.setOnClickListener(new Button.OnClickListener(){ 
    @Override 
    public void onClick(View arg0) { 
      //This line will set the orientation to landscape. 
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 
    } 
} 

您只需使用ACTIVITYINFO類中的值即可。

資源

ActivityInfo:https://developer.android.com/reference/android/content/pm/ActivityInfo.html#SCREEN_ORIENTATION_LANDSCAPE

景觀:https://developer.android.com/reference/android/content/pm/ActivityInfo.html#SCREEN_ORIENTATION_LANDSCAPE

肖像:https://developer.android.com/reference/android/content/pm/ActivityInfo.html#SCREEN_ORIENTATION_PORTRAIT

相關問題