Android 视频添加后如何获取视频视图的宽度和高度
视频视图的布局xml: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"
<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()就可以工作了。关于这个问题,你还有别的解决办法吗。?