If you want to draw the lines dynamically as per your screen size then you should use the following code in your camera preview class.
@Override
protected void onDraw(Canvas canvas)
{
if(grid){
// Find Screen size first
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
int screenWidth = metrics.widthPixels;
int screenHeight = (int) (metrics.heightPixels*0.9);
// Set paint options
paint.setAntiAlias(true);
paint.setStrokeWidth(3);
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.argb(255, 255, 255, 255));
canvas.drawLine((screenWidth/3)*2,0,(screenWidth/3)*2,screenHeight,paint);
canvas.drawLine((screenWidth/3),0,(screenWidth/3),screenHeight,paint);
canvas.drawLine(0,(screenHeight/3)*2,screenWidth,(screenHeight/3)*2,paint);
canvas.drawLine(0,(screenHeight/3),screenWidth,(screenHeight/3),paint);
}
}
You also need to add the following line in the constructor of your camera preview class:
this.setWillNotDraw(false);