Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.graphics.Canvas;

import android.graphics.Paint;

import android.graphics.Rect;
import android.graphics.RectF;

public class Main {
    public static void drawTextCenter(Canvas canvas, RectF rectf, String s, Paint paint) {
        Rect rect = new Rect();
        paint.getTextBounds(s, 0, s.length(), rect);
        canvas.drawText(s, rectf.left + (rectf.width() - (float) rect.width()) / 2.0F,
                rectf.top + (rectf.height() + (float) rect.height()) / 2.0F, paint);
    }

    public static void drawTextCenter(Canvas canvas, RectF rectf, String s, String s1, Paint paint, Paint paint1) {
        Rect rect = new Rect();
        paint.getTextBounds(s, 0, s.length(), rect);
        float f = rectf.left + (rectf.width() - (float) rect.width()) / 2.0F;
        float f1 = rectf.top + (rectf.height() + (float) rect.height()) / 2.0F;
        canvas.drawText(s, f, f1, paint);
        Rect rect1 = new Rect();
        paint1.getTextBounds(s, 0, s.length(), rect1);
        canvas.drawText(s1, 6F + (f + (float) rect.width()), (f1 - (float) rect.height()) + (float) rect1.height(),
                paint1);
    }
}