How to center text in an android view class? -
When I have a class that I see, how can I draw text in the center of the scene? To attract text I am using In the spirit, on the right track of Maver1ck, though In practice it is a bit more difficult than that. You have to set up a Now, to determine how to orient the text vertically Want Center on Visible Text? Do you want the baseline at the center? Do you want a center based on text top or climb? For the simplest case of the text, suppose we will center the center of the top and bottom of the font (note that this is not the full top and bottom - it will be the ascending and the descent): Then, your canvas.drawText , but when you can not take the text after dragging it, then I'm not sure how I will focus this text. . So how do I focus text in Android view class
TextPaint and have to do some measurements:
textpaint paint = new textpaint (paint.ntiiaias_flag.paint.sppINENETFTAFLG); Paint.setTextAlign (Paint.Align.CENTER); // Draw text from the center // Set any text size or color attributes
// Do it somewhere where you can cache it - there is no need to do this on each draw // onSizeChanged () is a good place Font Matrix Matrix = Paint. Gatefont Matrix (); Float height = monastery Box (metrics matte - matrix.bottom); Float x = getWidth () / 2; Float y = (getHeight () / 2) + (height / 2);
onDraw () :
canvas.drawText ("My Text", x, y, paint) ;
Comments
Post a Comment