Draw a rectangle with float values : Rectangle « 2D Graphics « Android

Draw a rectangle with float values

package app.test;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Bundle;
import android.widget.ImageView;

public class Test extends Activity {
  ImageView drawingImageView;

  public void onCreate(Bundle savedInstanceState) {
    drawingImageView = (ImageView) this.findViewById(R.id.DrawingImageView);
    Bitmap bitmap = Bitmap.createBitmap((int) getWindowManager()
        .getDefaultDisplay().getWidth(), (int) getWindowManager()
        .getDefaultDisplay().getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    // RectF Rectangle

    Paint paint = new Paint();
    float leftx = 20;
    float topy = 20;
    float rightx = 50;
    float bottomy = 100;
    RectF rectangle = new RectF(leftx, topy, rightx, bottomy);
    canvas.drawRect(rectangle, paint);



Related examples in the same category

1.Draw a rectangle
2.Round Rectangles