问题
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