From f271fd584b62f780be32660d006742320329341d Mon Sep 17 00:00:00 2001 From: maning <154292322@qq.com> Date: Wed, 18 Aug 2021 12:24:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BD=91=E6=A0=BC=E6=89=AB=E6=8F=8F=E7=BA=BF?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/android/view/ViewfinderView.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/libraryzxing/src/main/java/com/google/zxing/client/android/view/ViewfinderView.java b/libraryzxing/src/main/java/com/google/zxing/client/android/view/ViewfinderView.java index 31dad8e..1e2357e 100755 --- a/libraryzxing/src/main/java/com/google/zxing/client/android/view/ViewfinderView.java +++ b/libraryzxing/src/main/java/com/google/zxing/client/android/view/ViewfinderView.java @@ -338,7 +338,12 @@ private void drawGridScanner(Canvas canvas, Rect frame) { int stroke = 2; paintLaser.setStrokeWidth(stroke); //计算Y轴开始位置 - int startY = gridHeight > 0 && linePosition - frame.top > gridHeight ? linePosition - gridHeight : frame.top; + int startY; + if(gridHeight > 0 && linePosition - frame.top > gridHeight){ + startY = linePosition - gridHeight; + }else{ + startY = frame.top; + } LinearGradient linearGradient = new LinearGradient(frame.left + frame.width() / 2, startY, frame.left + frame.width() / 2, linePosition, new int[]{shadeColor(laserColor), laserColor}, new float[]{0, 1f}, LinearGradient.TileMode.CLAMP); //给画笔设置着色器 @@ -347,8 +352,18 @@ private void drawGridScanner(Canvas canvas, Rect frame) { float wUnit = frame.width() * 1.0f / gridColumn; float hUnit = wUnit; //遍历绘制网格纵线 - for (int i = 1; i < gridColumn; i++) { - canvas.drawLine(frame.left + i * wUnit, startY, frame.left + i * wUnit, linePosition, paintLaser); + for (int i = 0; i <= gridColumn; i++) { + float startX; + float stopX; + if (i == 0) { + startX = frame.left + 1; + } else if (i == gridColumn) { + startX = frame.left + i * wUnit - 1; + } else { + startX = frame.left + i * wUnit; + } + stopX = startX; + canvas.drawLine(startX, startY, stopX, linePosition, paintLaser); } int height = gridHeight > 0 && linePosition - frame.top > gridHeight ? gridHeight : linePosition - frame.top; //遍历绘制网格横线 @@ -377,7 +392,7 @@ public void startAnimation() { if (anim != null && anim.isRunning()) { return; } - anim = ValueAnimator.ofInt(frame.top + margin, frame.bottom - margin); + anim = ValueAnimator.ofInt(frame.top, frame.bottom); anim.setRepeatCount(ValueAnimator.INFINITE); anim.setRepeatMode(ValueAnimator.RESTART); anim.setDuration(2400);