We used to find the rectangle which fits the given text, for example if give "TESTING" in gettextbounds api it will give a rectangle that fits the given string "TESTING", but could any plz clarify on which basis the rectangle length is calculated, whether the font size will be considered if so is it possible for me to check like this ?
1) Way i tried CharSequence text = getText(); canvas.drawText(text, 0, text.length(), mTextX, mTextY, getPaint());
Paint pt = new Paint ( );
pt.setTextSize(10);
TextPaint tp = getPaint();
String string = "haa";
Rect currentBounds = new Rect ( );
//this.setTextSize(/* TypedValue.COMPLEX_UNIT_PX */ 10, /* fontPixelSize*Home.fltFontRatio */ 32);
tp.getTextBounds((String) text, 0, text.length(), currentBounds );
Log.e ( " ", "Desired Text " +text);
Log.e ( " ", "first Ondraw Left " +currentBounds.left);
Log.e ( " ", "Ondraw Top" +currentBounds.top);
Log.e ( " ", "Ondraw right " +currentBounds.right);
Log.e ( " ", "Ondraw bottom " +currentBounds.bottom);
pt.setTextSize(20);
tp.getTextBounds((String) text, 0, text.length(), currentBounds );
Log.e ( "", "Desired Text " +text);
Log.e ( " ", "Second Ondraw Left " +currentBounds.left);
Log.e ( " ", "Ondraw Top" +currentBounds.top);
Log.e ( " ", "Ondraw right " +currentBounds.right);
Log.e ( "Nrace ", "Ondraw bottom " +currentBounds.bottom);
2) Second way i tried
TextPaint tp = getPaint();
String string = "haa";
Rect currentBounds = new Rect ( );
this.setTextSize(/* TypedValue.COMPLEX_UNIT_PX */ 10, /* fontPixelSize*Home.fltFontRatio */ 32);
tp.getTextBounds(string, 0, string.length(), currentBounds );
Log.e ( " ", "first Left " +currentBounds.left);
Log.e ( " ", "Top" +currentBounds.top);
Log.e ( " ", "right " +currentBounds.right);
Log.e ( " ", "bottom " +currentBounds.bottom);
this.setTextSize(/* TypedValue.COMPLEX_UNIT_PX */ 10, /* fontPixelSize*Home.fltFontRatio */ 10);
tp.getTextBounds(string, 0, string.length(), currentBounds );
Log.e ( " ", "Sefond Left " +currentBounds.left);
Log.e ( " ", "Top" +currentBounds.top);
Log.e ( " ", "right " +currentBounds.right);
Log.e ( "", "bottom " +currentBounds.bottom);
In the above two methods am trying to find out the various rectangle size for the given text size. if this is not a good way plz advise me by posting some sample codes. Simply to say i have to find the various rectangle which fits the text "TESTING" for various font size.
Thanks in advance.