您的位置:首页 > 其它

VideoView控件可以手动改变大小

2014-12-05 15:19 148 查看
Android中的videoview控件在android中不能设置宽高,需要重写videoView中的onMeasure()方法,才可以设置videoview的宽和高。重写的videoview代码如下:

让VideoView可以手动的设置长宽

/**
* The CustomVideoView is to make videoView view length-width based on the parameters you set to decide.
* @author peter.
*
*/
public class CustomVideoView extends VideoView {
private int mVideoWidth;
private int mVideoHeight;

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

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

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

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
/* The following code is to make videoView view length-width
based on the parameters you set to decide. */
int width = getDefaultSize(mVideoWidth, widthMeasureSpec);
int height = getDefaultSize(mVideoHeight, heightMeasureSpec);
setMeasuredDimension(width, height);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: