2011-09-07 11 views

risposta

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

La classe Paint ha un metodo measureText(), che vi darà la larghezza in float

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

e un altro è 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); 

quindi effettuare la chiamata di

bounds.width(); 

bounds.height(); 
Problemi correlati