背景
当时是Tv项目中涉及到视频的大小窗播放的这样一个功能 ,当时我想到的是就是给 VideoView 设置一个单独的布局 从而对此布局进行操作 上代码:
首先先你的onCreate方法里
int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.EXACTLY);
int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
mainLl.measure(w, h);
//获取你原来布局的宽高
int measuredHeight = mainLl.getMeasuredHeight();
int measuredWidth = mainLl.getMeasuredWidth();
//这是你的布局距离上下左右的边距
//topMargin 上 leftMargin 左 rightMargin 右 bottomMargin 下
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams)
mainLl.getLayoutParams();
int topMargin = params.topMargin;
int leftMargin = params.leftMargin;
int rightMargin = params.rightMargin;
int bottomMargin = params.bottomMargin;
全屏的处理代码
//你要设置的 FrameLayout 我这里用的是帧布局
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
//mainLl你的布局id
mainLl.setLayoutParams(params);
缩小的处理代码
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(measuredWidth , measuredHeight );
layoutParams.setMargins(leftMargin, topMargin, rightMargin , bottomMargin);
mainLl.setLayoutParams(layoutParams);