通過使用此代碼解決。
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT
);
private void enterFullScreen(){
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
mVideoView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
mVideoView.setLayoutParams(layoutParams);
}
private void exitFullScreen(){
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
mVideoView.setSystemUiVisibility(0);
isFullScreen = false;
mFullScreen.setVisibility(View.INVISIBLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_TOP);
layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_LEFT);
layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT);
}else {
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,0);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP,0);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT,0);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,0);
}
mFullScreen.setVisibility(View.VISIBLE);
enter code here`enter code here`
mVideoView.setLayoutParams(layoutParams);
}
您是否嘗試過您提到的問題中提供的答案? – SilverNak
是的,但沒有奏效 –