android:screenOrientation ="portrait"在 Jellybean 中被忽略

标签 android screen-orientation android-4.2-jelly-bean

android:screenOrientation="portrait"在 Jellybean 中被忽略。如果我 Handlebars 机变成横屏,它无论如何都会改变方向。我试过好几部手机。我必须使用任何新标志吗?

最佳答案

您可以尝试以编程方式进行,

@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;
        }
    }

关于android:screenOrientation ="portrait"在 Jellybean 中被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13844577/

相关文章:

android - 当我尝试在设备上安装已编译的 .apk 时,INSTALL_FAILED_UPDATE_INCOMPATIBLE

Android Jelly Bean MeasureSpec 错误

Android Studio 0.2.8 TODO 颜色已更改

android - 在 Fragment 中使用 GoogleApiClient 时递归进入 executePendingTransactions

android - 旋转手机时 Activity 屏幕不旋转

ios - 设置列数和固定行数

android - Systrace 空白创建的 html 文件

android - 在 TextWatcher 中检测退格键

java - Android Studio - 从膨胀 View 自动创建 java 类变量

ios - 为什么 shouldAutorotateToInterfaceOrientation 方法标记为不可用?