Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 视频添加后如何获取视频视图的宽度和高度_Android_Video_Height_Width_Android Videoview - Fatal编程技术网

Android 视频添加后如何获取视频视图的宽度和高度

Android 视频添加后如何获取视频视图的宽度和高度,android,video,height,width,android-videoview,Android,Video,Height,Width,Android Videoview,视频视图的布局xml: <RelativeLayout android:id="@+id/videoEditorParent" android:layout_width="match_parent" android:layout_height="400dp"> <RelativeLayout android:id="@+id/vidEditorWrapper"

视频视图的布局xml:

   <RelativeLayout
        android:id="@+id/videoEditorParent"
        android:layout_width="match_parent"
        android:layout_height="400dp">

        <RelativeLayout
            android:id="@+id/vidEditorWrapper"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="@color/colorAccent">

            <VideoView
                android:id="@+id/vidEditor"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </RelativeLayout>

    </RelativeLayout>
            viewWidth = vidEditor.getWidth();
            viewHeight = vidEditor.getHeight();

            ViewGroup.LayoutParams layoutParams = vidEditorWrapper.getLayoutParams();

            dpWidthView = utilities.pxToDp(viewWidth);
            dpHeightView = utilities.pxToDp(viewHeight);

            dpWidthViewPerVal = (dpWidthView * 2) / 100;

            layoutParams.width = viewWidth;
            layoutParams.height = viewHeight;
            vidEditorWrapper.setLayoutParams(layoutParams);
我的屏幕截图:

   <RelativeLayout
        android:id="@+id/videoEditorParent"
        android:layout_width="match_parent"
        android:layout_height="400dp">

        <RelativeLayout
            android:id="@+id/vidEditorWrapper"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="@color/colorAccent">

            <VideoView
                android:id="@+id/vidEditor"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </RelativeLayout>

    </RelativeLayout>
            viewWidth = vidEditor.getWidth();
            viewHeight = vidEditor.getHeight();

            ViewGroup.LayoutParams layoutParams = vidEditorWrapper.getLayoutParams();

            dpWidthView = utilities.pxToDp(viewWidth);
            dpHeightView = utilities.pxToDp(viewHeight);

            dpWidthViewPerVal = (dpWidthView * 2) / 100;

            layoutParams.width = viewWidth;
            layoutParams.height = viewHeight;
            vidEditorWrapper.setLayoutParams(layoutParams);

我想要在videoview中播放视频的黑色区域的宽度和高度。 但是videoview的getWidth()或getMeasuredWidth()和getHeight()或getMeasuredHeight()给了我匹配的父宽度和高度


因此,如何获得videoview中覆盖的视频区域的宽度和高度(仅在图片中可见的暗区域,而非全宽)。尝试在PreparedListener中应用您的代码 例如:


首次调用onPrepared()时,这不起作用。但是,在调用onPause()和onResume()方法之后,onPrepared()就可以工作了。关于这个问题,你还有别的解决办法吗。?