scale Rect - Android Graphics

Android examples for Graphics:Rectangle

Description

scale Rect

Demo Code


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

public class Main {

    public static void scaleRect(RectF rect, float scale) {
        float w = rect.width();
        float h = rect.height();

        float newW = scale * w;
        float newH = scale * h;

        float dx = (newW - w) / 2;
        float dy = (newH - h) / 2;

        rect.left -= dx;//from  w ww.  j a v  a2s .  co m
        rect.top -= dy;
        rect.right += dx;
        rect.bottom += dy;
    }
}

Related Tutorials