Reputation: 133
Back with another question,
How do i draw 4 lines in onDraw? these are 4 constant lines with red color that represents my border of the view. i tried drawing and could only draw 1 line and even that wasnt in the same width as my screen.
Suggestions?
Thanks!
Upvotes: 1
Views: 2578
Reputation: 87064
Try:
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint redPaint = new Paint();
redPaint.setColor(Color.RED);
redPaint.setStrokeWidth(5); // set stroke so you can actually see the lines
canvas.drawLine(0, 0, getMeasuredWidth(), 0, redPaint);
canvas.drawLine(getMeasuredWidth(), 0, getMeasuredWidth(), getMeasuredHeight(), redPaint);
canvas.drawLine(getMeasuredWidth(), getMeasuredHeight(), 0, getMeasuredHeight(), redPaint);
canvas.drawLine(0, getMeasuredHeight(), 0, 0, redPaint);
}
Upvotes: 4
Reputation: 2300
void drawLine(float startX, float startY, float stopX, float stopY, Paint paint)
Draw a line segment with the specified start and stop x,y coordinates, using the specified paint.
#
Paint paint = new Paint();
paint.setColor(Color.Red);
onDraw( Canvas canvas){
canvas.drawLine(x,y,x1,y1, paint);
canvas.drawLine(x,y,x1,y1, paint);
canvas.drawLine(x,y,x1,y1, paint);
canvas.drawLine(x,y,x1,y1, paint);
}
change the value of (x,y) and (x1,y1)
Upvotes: 2