adjust Rectangle Center - Android Graphics

Android examples for Graphics:Rectangle

Description

adjust Rectangle Center

Demo Code


//package com.java2s;
import android.graphics.Rect;

public class Main {
    public static Rect adjustCenter(Rect rect, int x, int y) {
        return of(x, y, getRadius(rect));
    }//w  ww.  jav a 2 s. c  o  m

    public static Rect of(int centerX, int centerY, int radius) {
        return new Rect(centerX - radius, centerY - radius, centerX
                + radius, centerY + radius);
    }

    public static int getRadius(Rect square) {
        return square.centerX() - square.left;
    }
}

Related Tutorials