Draw rect on Canvas - Android Graphics

Android examples for Graphics:Canvas

Description

Draw rect on Canvas

Demo Code


//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 .ja  v  a2  s.c o  m*/
        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);
    }
}

Related Tutorials