2011-09-07 86 views

回答

8
Paint p = new Paint(); 
p.setTypeface(TypeFace obj); // if custom font use `TypeFace.createFromFile` 
p.setTextSize(float size); 
float textWidth = p.measureText("Your string"); 
// you get the width here and textsize is the height. 
2

的油漆類有一個方法measureText()這將給你的寬度在浮子

Paint p = new Paint(); 
int INFO_WINDOW_WIDTH = (int)p.measureText("this is string"); 

和另一個是Paint.getTextBounds

8
Paint mPaint = new Paint(); 
mPaint.setTextSize(/*put here ur size*/); 
mPaint.setTypeface(/* put here ur font type */); 
Rect bounds = new Rect(); 
mPaint.getTextBounds(text, 0, text.length(), bounds); 

然後使

呼叫
bounds.width(); 

bounds.height();