Code example for RectF

Methods: heightwidth

0
     * 横向、纵向居中 
     */ 
    protected void center(boolean horizontal, boolean vertical) {
        Matrix m = new Matrix();
        m.set(matrix);
        RectF rect = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
        m.mapRect(rect);
 
        float height = rect.height();
        float width = rect.width();
 
        float deltaX = 0, deltaY = 0;
 
        if (vertical) {
            // 图片小于屏幕大小,则居中显示。大于屏幕,上方留空则往上移,下方留空则往下移 
            int screenHeight = dm.heightPixels;
            if (height < screenHeight) {
                deltaY = (screenHeight - height) / 2 - rect.top;
            } else if (rect.top > 0) {
                deltaY = -rect.top;
Stop searching for code, let great code find you!  Add Codota to your java IDE