Here you can find the source of rect(Canvas canvas, int color, int stroke, float x, float y, float width, float height)
public static void rect(Canvas canvas, int color, int stroke, float x, float y, float width, float height)
//package com.java2s; import android.graphics.Canvas; import android.graphics.Paint; public class Main { public static void rect(Canvas canvas, int color, int stroke, float x, float y, float width, float height) { Paint paint = new Paint(); paint.setColor(color);/*from ww w . j av a 2 s .com*/ paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setStrokeWidth(stroke); float leftx = x; float topy = y; float rightx = x + width; float bottomy = y + height; canvas.drawRect(leftx, topy, rightx, bottomy, paint); } }