1 获取屏幕尺寸
WindowManager wm = this.getWindowManager();
viewWidth = wm.getDefaultDisplay().getWidth();
viewHeight = wm.getDefaultDisplay().getHeight();
计算比例
double scale_ratio = 0.9;
final int tv_width = (int) (scale_ratio * w_width);
final int tv_height = (int) (tv_width / 1.59);
2 设置控件参数
MarginLayoutParams params = (MarginLayoutParams) textView.getLayoutParams(); // 取控件当前的布局参数
params.width = tv_width;// 强制设置
params.height = tv_height;
textView.setLayoutParams(params); // 使设置好的布局参数应用到控件
3
// 触屏监听事件
mSurfaceView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// 首先相机功能正常
if (cameraAuthority) {
mCamera.autoFocus(autoFocusCallback);
}
return true;
}
});