android开发修改相机扫描二维码框的高宽

我用的是网上一个现成的例子,可以直接用,但是高宽不合适,现在主流都是大屏幕手机了,所以需要更改。

找到CameraManager 类,更改下面的方法

public Rect getFramingRect() {
    Point screenResolution = configManager.getScreenResolution();
    if (framingRect == null) {
      if (camera == null) {
        return null;
      }
      int width = screenResolution.x * 3 / 5;
//      if (width < MIN_FRAME_WIDTH) {
//        width = MIN_FRAME_WIDTH;
//      } else if (width > MAX_FRAME_WIDTH) {
//        width = MAX_FRAME_WIDTH;
//      }
      int height = screenResolution.y * 3 / 5;
//      if (height < MIN_FRAME_HEIGHT) {
//        height = MIN_FRAME_HEIGHT;
//      } else if (height > MAX_FRAME_HEIGHT) {
//        height = MAX_FRAME_HEIGHT;
//      }
        /* 自定义,以宽高其中一个窄的为正方形的边长 */
        width = (width>height?height:width);
        height = (width<height?height);
      int leftOffset = (screenResolution.x - width) / 2;
//      int topOffset = (screenResolution.y - height) / 2;
        int topOffset = (screenResolution.y - height) / 2 - 40;  /* 自定义,放上一点 */
      framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height);
      Log.d(TAG, "Calculated framing rect: " + framingRect);
    }
    return framingRect;
  }

下载链接:http://download.csdn.net/detail/feijian_/8275179

原文地址:https://www.cnblogs.com/feijian/p/4172561.html