如何实现videoview的动态布局全屏和半屏控制
发布网友
发布时间:2022-04-30 01:55
我来回答
共1个回答
热心网友
时间:2022-04-20 01:16
在你自定义的View中重写onMeasure方法
@Override
protected
void
onMeasure(int
widthMeasureSpec,
int
heightMeasureSpec)
{
int
width
=
getDefaultSize(0,
widthMeasureSpec);
int
height
=
getDefaultSize(0,
heightMeasureSpec);
setMeasuredDimension(width,
height);
}
2、按钮的事件中写上判断,视频的控件用相对布局包裹下
if(!fullscreen){//设置RelativeLayout的全屏模式
RelativeLayout.LayoutParams
layoutParams=
new
RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
mVideoView01.setLayoutParams(layoutParams);
fullscreen
=
true;//改变全屏/窗口的标记
}else{//设置RelativeLayout的窗口模式
RelativeLayout.LayoutParams
lp=new
RelativeLayout.LayoutParams(320,240);
lp.addRule(RelativeLayout.CENTER_IN_PARENT);
mVideoView01.setLayoutParams(lp);
fullscreen
=
false;//改变全屏/窗口的标记
}