导入过zxing的同学们 需要修改扫描框的样式 主要是修改这个属性
首先 自己自定义一个
继承ViewfinderVier 的类
public classCustomViewfinderViewextendsViewfinderView {
public intlaserLinePosition=0;
public float[]position=new float[]{0f,0.5f,1f};
public int[]colors=new int[]{0x0047ac31,0xffff0fff,0x00ffff0f};
publicLinearGradientlinearGradient;
publicCustomViewfinderView(Context context, AttributeSet attrs) {
super(context, attrs);
}
/**
* 重写draw方法绘制自己的扫描框
*
*@paramcanvas
*/
@Override
public voidonDraw(Canvas canvas) {
refreshSizes();
if(framingRect==null||previewFramingRect==null) {
return;
}
Rect frame =framingRect;
Rect previewFrame =previewFramingRect;
intwidth = canvas.getWidth();
intheight = canvas.getHeight();
//绘制4个角
paint.setColor(0xFF47ac31);
canvas.drawRect(frame.left, frame.top, frame.left+70, frame.top+10,paint);
canvas.drawRect(frame.left, frame.top, frame.left+10, frame.top+70,paint);
canvas.drawRect(frame.right-70, frame.top, frame.right, frame.top+10,paint);
canvas.drawRect(frame.right-10, frame.top, frame.right, frame.top+70,paint);
canvas.drawRect(frame.left, frame.bottom-10, frame.left+70, frame.bottom,paint);
canvas.drawRect(frame.left, frame.bottom-70, frame.left+10, frame.bottom,paint);
canvas.drawRect(frame.right-70, frame.bottom-10, frame.right, frame.bottom,paint);
canvas.drawRect(frame.right-10, frame.bottom-70, frame.right, frame.bottom,paint);
// Draw the exterior (i.e. outside the framing rect) darkened
paint.setColor(resultBitmap!=null?resultColor:maskColor);
canvas.drawRect(0,0, width, frame.top,paint);
canvas.drawRect(0, frame.top, frame.left, frame.bottom+1,paint);
canvas.drawRect(frame.right+1, frame.top, width, frame.bottom+1,paint);
canvas.drawRect(0, frame.bottom+1, width, height,paint);
if(resultBitmap!=null) {
// Draw the opaque result bitmap over the scanning rectangle
paint.setAlpha(CURRENT_POINT_OPACITY);
canvas.drawBitmap(resultBitmap,null, frame,paint);
}else{
// paint.setAlpha(SCANNER_ALPHA[scannerAlpha]);
// scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length;
intmiddle = frame.height() /2+ frame.top;
laserLinePosition=laserLinePosition+5;
if(laserLinePosition> frame.height()) {
laserLinePosition=0;
}
linearGradient=newLinearGradient(frame.left+1, frame.top+laserLinePosition, frame.right-1, frame.top+10+laserLinePosition,colors,position, Shader.TileMode.CLAMP);
// Draw a red "laser scanner" line through the middle to show decoding is active
// paint.setColor(laserColor);
paint.setShader(linearGradient);
//绘制扫描线
canvas.drawRect(frame.left+1, frame.top+laserLinePosition, frame.right-1, frame.top+10+laserLinePosition,paint);
paint.setShader(null);
floatscaleX = frame.width() / (float) previewFrame.width();
floatscaleY = frame.height() / (float) previewFrame.height();
ListcurrentPossible =possibleResultPoints;
ListcurrentLast =lastPossibleResultPoints;
intframeLeft = frame.left;
intframeTop = frame.top;
if(currentPossible.isEmpty()) {
lastPossibleResultPoints=null;
}else{
possibleResultPoints=newArrayList<>(5);
lastPossibleResultPoints= currentPossible;
paint.setAlpha(CURRENT_POINT_OPACITY);
paint.setColor(resultPointColor);
for(ResultPoint point : currentPossible) {
canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX),
frameTop + (int) (point.getY() * scaleY),
POINT_SIZE,paint);
}
}
if(currentLast !=null) {
paint.setAlpha(CURRENT_POINT_OPACITY/2);
paint.setColor(resultPointColor);
floatradius =POINT_SIZE/2.0f;
for(ResultPoint point : currentLast) {
canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX),
frameTop + (int) (point.getY() * scaleY),
radius,paint);
}
}
postInvalidateDelayed(16,
frame.left,
frame.top,
frame.right,
frame.bottom);
// postInvalidate();
}
}
}
然后自己再画一个布局
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/zxing_barcode_surface"
app:zxing_framing_rect_width="250dp"
app:zxing_framing_rect_height="250dp">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/zxing_viewfinder_view"
app:zxing_possible_result_points="@color/zxing_custom_possible_result_points"
app:zxing_result_view="@color/zxing_custom_result_view"
app:zxing_viewfinder_laser="#FFFFFF"
app:zxing_viewfinder_mask="@color/zxing_custom_viewfinder_mask"/>
android:id="@+id/zxing_status_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:background="@color/zxing_transparent"
android:text="@string/zxing_msg_default_status"
android:textColor="@color/zxing_status_text"/>
最后 实现上头的第一步应用这个布局就行
在<com.journeyapps.barcodescanner.DecoratedBarcodeView>中的 app:zxing_scanner_layout=“” 这个属性引用自己自定义的扫描框就行