安卓视频开发中。往往需要动态设置录视频宽高比。
``` java
//声明预览的宽高和屏幕宽高private int previewWidth = 480, screenWidth = 480;
private int previewHeight = 480, screenHeight = 800;
//初始化
screenWidth = displaymetrics.widthPixels;
screenHeight = displaymetrics.heightPixels;
RelativeLayout.LayoutParams layoutParam1 = new RelativeLayout.LayoutParams(screenWidth,(int) (screenWidth*(previewWidth/(previewHeight*1f))));
layoutParam1.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
RelativeLayout.LayoutParams layoutParam2 = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
layoutParam2.topMargin = screenWidth;
View view = new View(FFmpegRecorderActivity.this);
view.setFocusable(false);
view.setBackgroundColor(Color.BLACK);
view.setFocusableInTouchMode(false);
topLayout.addView(cameraView, layoutParam1);
topLayout.addView(view,layoutParam2);
topLayout.setOnTouchListener(FFmpegRecorderActivity.this);
```
之后放入到topLayout中。这个是录视频surfaceView的声明。