【问题标题】:Center video at center of screen - Videoview Android在屏幕中心居中视频 - Videoview Android
【发布时间】:2016-04-27 13:32:08
【问题描述】:

我有一个视频视图,播放某个视频这是他的 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>

我正在尝试将视频置于其中,但每当我播放视频时, 它不会出现在中心,并且位置会根据视频有所变化,如何将其居中?

【问题讨论】:

标签: android android-layout android-videoview


【解决方案1】:

正如@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 位置

【讨论】:

    【解决方案2】:

    在我的情况下,我只需要使用 android:layout_gravity="center" 将实际的 VideoView 居中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-19
      • 2015-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-18
      • 2015-07-15
      相关资源
      最近更新 更多