Android 修改VideoView的宽

来源:互联网 发布:北航网络教育好毕业吗? 编辑:程序博客网 时间:2024/06/04 00:45
自定义VideoView,进行按照布局全屏显示视频
解决办法是重写onMeasure方法
public class MyVideoView extends VideoView {    public MyVideoView(Context context) {        this(context, null);    }    public MyVideoView(Context context, AttributeSet attrs) {        super(context, attrs);    }    public MyVideoView(Context context, AttributeSet attrs, int defStyleAttr) {        this(context, attrs);    }    public MyVideoView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {        this(context, attrs, defStyleAttr);    }    //重写测量方法,让视频按照布局显示    @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);    }}


0 0