问题描述:在使用VideoView播放视频文件时,如果视频的分辨率较小就会出现视频跑偏(不在屏幕中央等情况)可以通过重写VideoView来解决该问题;
public class CtsCustomVideoView extends VideoView {
public CtsCustomVideoView(Context context) {
super(context, null);
}
public CtsCustomVideoView(Context context, AttributeSet attrs) {
super(context, attrs, 0);
}
public CtsCustomVideoView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = getDefaultSize(0, widthMeasureSpec);
int height = getDefaultSize(0, heightMeasureSpec);
setMeasuredDimension(width, height);
}
}
通过设置VideoView的setMeasureDimension()方法便可解决该问题。