Skip to content

Commit

Permalink
网格扫描线优化
Browse files Browse the repository at this point in the history
  • Loading branch information
maning0303 committed Aug 18, 2021
1 parent 7e75a44 commit f271fd5
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
//给画笔设置着色器
Expand All @@ -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;
//遍历绘制网格横线
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f271fd5

Please sign in to comment.