Fullscreen VideoView not centered

I use this XML layout to show a full-screen VideoView in my activity. The video is fullscreen, but it is not centered. In landscape mode, it remains on the left side of the screen and leaves a few spaces on the right side of the screen.

How can I make my VideoView set to the center of the 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> 
+4
source share
4 answers

Try this layout,

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center"> <VideoView android:id="@+id/videoview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true"/> </RelativeLayout> 
+10
source

Try the following:

 <?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_height="fill_parent" android:layout_centerInParent="true"> </VideoView> </RelativeLayout> 

Hope this helps.

+3
source

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

And here you can see how to handle orientation changes.

It can be a layout to make video viewing in full screen.

0
source

If your VideoView cannot focus on a RelativeLayout, you can try putting it in a FrameLayout like this:

 <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"> <VideoView android:id="@+id/video_view" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center"> </VideoView> </FrameLayout> 

And then put it in a RelativeLayout.

-1
source

Source: https://habr.com/ru/post/1411541/


All Articles