今天在使用VideoView的时候,发现对原生的VideoView设置layout_width属性时,发现即使“fill_parent”也无法是视频充满屏幕,后来通过自定义VideoView的方式,解决了这个问题。事实上,有很多控件都会发生这样的问题,必须要通过重写onMeasuer()方法,来解决该问题:
<span style="font-family:Microsoft YaHei;font-size:18px;">public class CustomVideoView extends VideoView {
public CustomVideoView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = getDefaultSize(0, widthMeasureSpec);
int height = getDefaultSize(0, heightMeasureSpec);
setMeasuredDimension(width, height);
}
}</span>