get Rect Center X - Android Graphics

Android examples for Graphics:Rectangle

Description

get Rect Center X

Demo Code


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

public class Main {
    public static int getCenterX(Rect rect) {
        return Math.round(rect.left + (rect.right - rect.left) / 2);
    }/*from   ww w  . ja va2  s  .  c o  m*/

    public static float getCenterX(RectF rect) {
        return (rect.left + (rect.right - rect.left) / 2);
    }
}

Related Tutorials