获取文字的宽度(android)
在开发中,有时候要获取文字的宽度以更好的布局
- Paint mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
- mTextPaint.setColor(Color.WHITE);
- // Define the string.
- String displayText = “Hello World!”;
- // Measure the width of the text string.
- float textWidth = mTextPaint.measureText(displayText);