居中视频在屏幕中央 - Videoview Android

Center video at center of screen - Videoview Android

我有一个视频视图,播放某个视频这是他的 xml

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



Some other views


    <VideoView
        android:id = "@+id/video"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_gravity="center"
        android:layout_alignParentStart="true"
        />



</RelativeLayout>

我试图将视频置于其中,但每当我播放视频时, 它没有出现在中心位置,位置根据视频有点变化,如何居中?

正如@jaydroider 所说,您可以使用 layout_centerInParent=true

在此示例中,我更改了宽度和高度并更改了主布局的背景颜色。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:background="@android:color/white">

    <VideoView
        android:id="@+id/video"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_centerInParent="true"
        android:layout_gravity="center" />

</RelativeLayout>

不要使用 android:layout_alignParentTop="true"android:layout_alignParentStart="true"因为如果你使用它,布局总是显示在TOP/LEFT位置

在我的例子中,我只需要使用 android:layout_gravity="center" 将实际的 VideoView 居中到中心