阅读:5493回复:1

VideoView视频尺寸的问题

楼主#
更多 发布于:2019-10-11 13:38
使用VideoView播放视频时,发现有的屏幕尺寸上,视频没有全屏,有的是右边一块空白,有的是下面空白。这个时候可以自定义一个VideoView,重写onMeasure()方法,重新计算一下高度和宽度。这样就是全屏播放了


public class MyVideoView extends VideoView {


 public MyVideoView(Context context) {
 super(context);
 }


 public MyVideoView(Context context, AttributeSet attrs) {
 super(context, attrs);
 }


 public MyVideoView(Context context, AttributeSet attrs, int defStyle) {
 super(context, attrs, defStyle);
 }


 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
 // 我们重新计算高度
 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
 int width = getDefaultSize(0, widthMeasureSpec);
 int height = getDefaultSize(0, heightMeasureSpec);
 setMeasuredDimension(width, height);
 }
}



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


    <com.itemp.urlhome.MyVideoView
        android:id="@+id/vv"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


</LinearLayout>

最新喜欢:

VastStarGamesVastSt...
[url]http://190.lsal.cn/195/1329.gif?0728100424873[/url]
沙发#
发布于:2019-10-15 09:12
[url]http://190.lsal.cn/195/1329.gif?0728100424873[/url]
游客

返回顶部