Code example for TextPaint

Methods: getTextSize, measureText

0
            reqWidth = widthSize;
             
        } else { 
        	 
            // find out the total pixel size required for first and last text 
            reqWidth = (int)(strokePaint.measureText(getText().toString()))+10;
        } 
         
        // find out Height based on heightMode 
        if (heightMode == MeasureSpec.EXACTLY) {
        	 
            // set user specified Height 
            reqHeight = heightSize;
             
        } else { 
        	 
            // get the default height of the Font 
            reqHeight = (int) strokePaint.getTextSize();
        } 
         
        // set the calculated width and height of your drawing area 
        setMeasuredDimension(reqWidth, reqHeight+10);
    }