可以在这找到解决方式:
http://stackoverflow.com/questions/26797321/not-able-to-convert-zxing-into-portrait-mode-in-android
重要的第二步
2 I在 CameraManager 类, 方法getFramingRect 替换
int width = MIN_FRAME_WIDTH; int height = MIN_FRAME_HEIGHT; if (context.getResources().getConfiguration().orientation ==Configuration.ORIENTATION_PORTRAIT) { int tmp = 7 * screenResolution.x / 8; width = (tmp) < MIN_FRAME_WIDTH ? MIN_FRAME_WIDTH : (tmp); tmp = 1 * screenResolution.y / 3; height = (tmp) < MIN_FRAME_WIDTH ? MIN_FRAME_WIDTH : ((tmp) > MAX_FRAME_HEIGHT ? MAX_FRAME_HEIGHT : (tmp)); }else{ // 原始代码 width = findDesiredDimensionInRange(screenResolution.x, MIN_FRAME_WIDTH, > MAX_FRAME_WIDTH); height = findDesiredDimensionInRange(screenResolution.y, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT); }
正确显示扫描框。
老版本没有
findDesiredDimensionInRange
这个方法
加上
private static int findDesiredDimensionInRange(int resolution, int hardMin, int hardMax) {
int dim = 5 * resolution / 8; // Target 5/8 of each dimension
if (dim < hardMin) {
return hardMin;
}
if (dim > hardMax) {
return hardMax;
}
return dim;
}
原文地址:http://springserver.blog.51cto.com/6150384/1594758