关于android videoview视频不能匹配整个videoview控件的问题

来源:互联网 发布:钉钉办公软件有mac版 编辑:程序博客网 时间:2024/06/05 04:03

其实就是官方API的videoview.class里面的onmeasure的问题

解决方法如下:

1.新建一个VideoView类,继承android.widget.VideoView

2.新建的这个类重写onmeasure方法

代码如下:

public class VideoView extends android.widget.VideoView {
private int mVideoWidth;
private int mVideoHeight;


public VideoView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}


public VideoView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}


public VideoView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}

//上述三个方法一定要存在,否则xml会报arguement错

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

int width = getDefaultSize(mVideoWidth, widthMeasureSpec);
int height = getDefaultSize(mVideoHeight, heightMeasureSpec);
setMeasuredDimension(width, height);
}


}


3.控件xml改为

<xxx.VideoView
        android:id="@+id/video"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


其中xxx是你的重写的VideoView所在包名。


其实就是屏蔽了官方API,onmeasure方法里面的那一堆if判断,直接设置视频长宽。

0 0
原创粉丝点击