Paint.gettextbounds() Returns To Big Height
EDIT: The problem came from the emulator, the error did not appear on a real device :( I'm trying to draw some text in a custom view and must there for measure it but the value of
Solution 1:
i didnot test your code but i dont see any problems with Paint.getTextBounds():
publicclassTextBoundsTestextendsView {
private Paint paint;
private Rect bounds;
publicTextBoundsTest(Context context) {
super(context);
paint = newPaint(Paint.ANTI_ALIAS_FLAG);
paint.setTextSize(32);
bounds = newRect();
}
@OverrideprotectedvoidonDraw(Canvas canvas) {
Stringtext="this is my text";
paint.getTextBounds(text, 0, text.length(), bounds);
Log.d(TAG, "onDraw " + bounds);
intx= (getWidth() - bounds.width()) / 2;
inty=70;
paint.setColor(0xff008800);
bounds.offset(x, y);
canvas.drawRect(bounds, paint);
paint.setColor(0xffeeeeee);
canvas.drawText(text, x, y, paint);
}
}
add this in Activity.onCreate:
TextBoundsTestview=newTextBoundsTest(this);
setContentView(view);
the result is:
Post a Comment for "Paint.gettextbounds() Returns To Big Height"