所以我有这个代码,名为onConfigurationChanged:
private void setVideoLayoutParams(){
LinearLayout.LayoutParams params;
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){
// this works as expected
showNavigationAndStatusBars();
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
params = new LinearLayout.LayoutParams(size.x, size.x * 9 / 16);
}else{
hideNavigationAndStatusBars();
// this does not work properly
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
params = new LinearLayout.LayoutParams(size.x, size.y);
}
controller.setPauseButtonSize();
Log.d(TAG, "video layout params set : " + params.width + "/" + params.height);
videoFrame.setLayoutParams(params);
}
private void hideNavigationAndStatusBars(){
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
private void showNavigationAndStatusBars(){
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
decorView.setSystemUiVisibility(uiOptions);
}
当屏幕旋转为横向时,导航和状态栏会消失。但是我的videoFrame没有填满屏幕。
屏幕右侧的一小部分保持空白,等于导航栏的高度。 屏幕底部的另一小部分等于通知栏的高度仍为空白。
当创建参数时,我的记录器显示1794/1080。当我触摸屏幕时,我记录了videoFrame的大小,它显示了1794/1009。在两种情况下,我的猜测都应该显示为1800/1080。
我做错了什么?
答案 0 :(得分:0)
将您的Videoview置于相对布局中,并添加alignparentright,alignparentleft,alignparenttop和alignparentbottom“true”。这将是完美的。
答案 1 :(得分:0)
你的布局是这样的吗?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<VideoView android:id="@+id/myvideoview"
android:layout_width="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_height="fill_parent">
</VideoView>
</RelativeLayout>
然后尝试
DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
android.widget.LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) videoView.getLayoutParams();
params.width = metrics.widthPixels;
params.height = metrics.heightPixels;
params.leftMargin = 0;
videoView.setLayoutParams(params);