自定义view如何让文字在RectF居中

2019-02-25  本文已影响0人  三千世界_
        //显示单位文字
        Paint  clTxtPaint = new Paint();
        clTxtPaint.setTextSize(hintSize);
        clTxtPaint.setColor(Color.parseColor("#333333"));
        clTxtPaint.setTextAlign(Paint.Align.CENTER);
       RectF  r2=new RectF ();
       Paint.FontMetrics fm = clTxtPaint.getFontMetrics();
        canvas.drawText("开始测量", r2.centerX(), r2.centerY()- (fm.descent - (-fm.ascent + fm.descent)/2),clTxtPaint);
上一篇 下一篇

猜你喜欢

热点阅读