4

Jellybeanではandroid:screenOrientation="portrait"は無視されます。電話を横向きにすると、向きが変わります。私はいくつかの電話で試しました。使用しなければならない新しいフラグはありますか?

4

1 に答える 1

2

あなたはそれをプログラムでやろうとすることができます、

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    switch (newConfig.orientation)
    {
    case Configuration.ORIENTATION_PORTRAIT:
        // taking action on event
        lockScreenRotation(Configuration.ORIENTATION_PORTRAIT);
    break;
    case Configuration.ORIENTATION_LANDSCAPE:
        // taking action on event
        lockScreenRotation(Configuration.ORIENTATION_LANDSCAPE);
    break;
    case Configuration.ORIENTATION_SQUARE:
        // taking action on event
        lockScreenRotation(Configuration.ORIENTATION_SQUARE);
    break;
    default:
        throw new Exception("Unexpected orientation!!!");
    break;
 }




private void lockScreenRotation(int orientation)
    {
      // Stop the screen orientation changing during an event
        switch (orientation)
        {
        ...
      case Configuration.ORIENTATION_PORTRAIT:
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        break;
      case Configuration.ORIENTATION_LANDSCAPE:
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        break;
        ...
      case default:
       this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); 
       break;
        }
    }
于 2012-12-12T16:55:45.647 に答える