Android Video not fitting the width in portrait of the videoview and not occupying full screen in landscape

时光怂恿深爱的人放手 提交于 2019-12-04 07:38:28

You need to have two different layouts. One for the portrait and the one for the landscape. Create two xml files with the same name and put them into folders "layout-land" for landscape and "layout-port" for portrait.

And Here you can take a look how to handle orientation changes.

This can be the layout to make video view full screen.

<?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>

EDIT : This is How you can handle it in the method.

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

  // Checks the orientation of the screen
  if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
    Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
    setContentView(Your Landscape layout);
  } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
    Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
    setContentView(Your portrait layout);
  }
}

For linearlayout I'm not sure. But using relativelayout you can do this as below.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

<VideoView
    android:id="@+id/videoview"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true" >
</VideoView>

//your other xml content 
....
....
....

</RelativeLayout>

And If you want the videoview to be filled in height too. then you need to do this code:

<VideoView
    android:id="@+id/videoview"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentBottom="true">
</VideoView>

//your other xml content 
....
....
....

</RelativeLayout>

Let me know if it's helped. Thanks.

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