新手,看到视频播放的时候,动手弄了个最简单的布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<VideoView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/vv_show"/>
</LinearLayout>
在VideoVidw里面设置layout_width,layout_height,不管设置成match_parent还是wrap_content的,这个VideoView还是撑满了整个屏幕(程序就是一个简单的布局,除了自动代码以外,没有加一点代码),发现这里wrap_content就一点用都没有,请教前辈这个是什么问题
尺寸問題直接看
VideoView
的onMeasure()
方法VideoView
的onMeasure()
方法VideoView
的大小跟mVideoWidth
和mVideoHeight
有关, 看变量名字就知道是播放的媒体的实际尺寸, 你设置播放的媒体么? 大致看了下onMeasure()
VideoView
的大小跟mVideoWidth
和mVideoHeight
有關, 看變數名字就知道是播放的媒體的實際尺寸, 你設定播放的媒體麼?大致看了下onMeasure()
, 裡面的邏輯不是很複雜, 你可以自己看看, 大概就知道是什麼問題了🎜一般來說播放器都是要自己定義大小的 因為都會進行縮放,不能採用包裹內容的高度定義方式。
如一樓說的,要了解VideoView的版面渲染流程 你可以看看VideoView的源碼
原始碼裡面有
// no size yet, just adopt the given spec sizes
你沒有設定高度就給你預設空間的大小,也就是父容器的大小。就是全螢幕了。