onBackPressed() Orientation Issue

好久不见. 提交于 2019-12-12 19:53:37

问题


Activity supports Landscape mode

   <activity
        android:name=".MainActivity"
        android:configChanges="orientation|screenSize|keyboardHidden"
        android:screenOrientation="landscape"
        android:label="@string/app_name" >

where I have allocated 50% space to Video Player (using FrameLayout) and rest 50% to ListView.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <FrameLayout
        android:id="@+id/video_frame"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <ListView
        android:id="@+id/video_list_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

</LinearLayout>

Now, I have started playing video > moved to full screen mode > pressed back to exit full screen mode > getting Activity in Portrait mode (whereas I was expecting to get it in Landscape mode)

    boolean isFullScreen = false;

    @Override
    public void onGoToFullscreen() {
        isFullScreen = true;
        videoListView.setVisibility(View.INVISIBLE);
    }

    @Override
    public void onReturnFromFullscreen() {
        videoListView.setVisibility(View.VISIBLE);
    }

    @Override
    public void onBackPressed() {
        Log.d("boolean:-", Boolean.toString(isFullScreen));
        if(isFullScreen) {
            imaPlayer.getContentPlayer().setFullscreen(false);
        }
        else {
            super.onBackPressed();
        }
    }

回答1:


/* I am not sure,can you put this line of code in on back pressed method ? */

Log.d("boolean:-", Boolean.toString(isFullScreen));
    if(isFullScreen) {
        imaPlayer.getContentPlayer().setFullscreen(false);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
    else {
        super.onBackPressed();
    }


来源:https://stackoverflow.com/questions/36098317/onbackpressed-orientation-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!