Android VideoView 在 ScrollView 中填充时不展开

Android VideoView not expanding when populating inside a ScrollView

此视频视图不会展开并将我的视频放入视图中。如果我设置静态高度和宽度(例如 640dp 400dp),视频会成功填充视图并按预期工作。

这个问题是在我进入 ScrollView 设置后出现的 - 它曾经在它自己的父 LinearLayout 中工作正常。

XML,共 VideoView:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/gray">


    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/top_video"
            android:layout_alignParentTop="true"
            android:orientation="vertical"
            android:visibility="gone">

            <VideoView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="invisible"
                android:layout_centerInParent="true"
                android:id="@+id/video_view" />

        </RelativeLayout>

        <!---- many more layouts and views that all get hidden when setting above to visible -->
        <!---- many more layouts and views that all get hidden when setting above to visible -->

     </LinearLayout>
</ScrollView>

android:fillViewPort=true 添加到您的滚动视图并匹配父级高度

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:fillViewPort=true
    android:layout_height="match_parent"
    android:background="@color/gray">