Android把字繪到正中間

        Paint textPaint = new Paint();
        textPaint.setColor(getResources().getColor(R.color.your_color));
        textPaint.setAntiAlias(true);
        textPaint.setTextSize(TEXT_SIZE);
        textPaint.setStyle(Paint.Style.FILL);
        Paint.FontMetrics fm = textPaint.getFontMetrics();
        int txtHeight = (int) Math.ceil(fm.descent - fm.ascent);
        String txt = "100";
        float txtWidth = textPaint.measureText(txt, 0, txt.length());
        canvas.drawText(txt, xCenter - txtWidth / 2, yCenter + txtHeight / 4, textPaint);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章