全屏VideoView没有居中显示

4
我在我的活动中使用这个XML布局来显示全屏VideoView。视频是全屏的,但不是居中的。在横屏模式下,它停留在屏幕左侧,右侧留下一些空白区域。
如何让我的VideoView位于屏幕中央?
<?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>

尝试一下这个解决方案,希望对你有用。(https://dev59.com/q13Va4cB1Zd3GeqPC7Jn#20798009)按照Andro的建议进行布局,但使用fill parent而不是wrap content。 - Chirag Shah
3个回答

11

尝试使用这个布局:

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

1
RelativeLayout没有方向,但这个方法对我有效!应该被接受为正确答案。 - Guillaume
它在竖屏上不起作用。我看到视频对齐在屏幕顶部。 - bashan

3

试试这个:

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

希望这可以帮到您。

它在竖屏上无法工作。我看到视频在屏幕顶部。 - bashan

-1
如果您的VideoView无法在RelativeLayout中居中,可以尝试将其放入FrameLayout中,如下所示:
<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>

然后将其放入RelativeLayout中。


它在竖屏模式下无法工作。我仍然看到视频对齐到屏幕顶部。 - bashan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接