更改android中的屏幕方向

时间:2015-02-13 10:02:36

标签: android screen-orientation

我想在帧布局可见时(即视频正在全屏播放)将屏幕方向更改为 SENSOR ,这样工作正常,但我想将其还原为 PORTRAIT 当帧布局消失哪个不起作用(没有错误,但代码没有做任何事情)我到目前为止已尝试过这个

// Finally show the custom view container.
        mCustomViewContainer.setVisibility(View.VISIBLE);
        mCustomViewContainer.bringToFront();

        // auto orientation change if video is playing
        if (mCustomViewContainer.getVisibility() == View.VISIBLE) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
        } else {        
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }       
    }

我找到的解决方法是改变方向,因为我隐藏了我的框架布局

@Override
public void onBackPressed() {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    exitdlg = (View) findViewById(R.id.exitdlg);
    options1 = (View) findViewById(R.id.options1);
    if (mCustomView != null) {// close full screen video view if open
        mWebChromeClient.onHideCustomView();// FULL-SCREEN VIDEO-5
    } else if (options1.getVisibility() == View.VISIBLE) {
        findViewById(R.id.options1).setVisibility(View.GONE);

    } else if (exitdlg.getVisibility() == View.GONE) {// this brings
                                                        // up/hides
        // menu 1 on hardware
        // options btn
        // Its visible
        findViewById(R.id.exitdlg).setVisibility(View.VISIBLE);
    } else {
        // Either gone or invisible
        findViewById(R.id.exitdlg).setVisibility(View.GONE);

    }
}

但只有按下我不想要的按钮两次才有效。 that's我得到了这段代码

0 个答案:

没有答案