code: private void refitText() {
          if (!mSizeToFit) {
              return;
          }
  
          if (mMaxLines <= 0) {
              // Don't auto-size since there's no limit on lines.
              return;
          }
  
          String text = mTextView.getText().toString();
          int targetWidth = mTextView.getWidth() - mTextView.getPaddingLeft() - mTextView.getPaddingRight();
          if (targetWidth > 0) {
              Context context = mTextView.getContext();
              Resources r = Resources.getSystem();
              DisplayMetrics displayMetrics;
  
              float size = mMaxTextSize;
              float high = size;
              float low = 0;
  
              if (context != null) {
                  r = context.getResources();
              }
              displayMetrics = r.getDisplayMetrics();
  
              mPaint.set(mTextView.getPaint());
              mPaint.setTextSize(size);
  
              if ((mMaxLines == 1 && mPaint.measureText(text) > targetWidth)
                      || getLineCount(text, mPaint, size, targetWidth, displayMetrics) > mMaxLines) {
                  size = getTextSize(text, mPaint, targetWidth, mMaxLines, low, high, mPrecision,
                          displayMetrics);
              }
  
              if (size < mMinTextSize) {
                  size = mMinTextSize;
              }
  
              mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
          }
      }
docs: Re size the font so the specified text fits in the text box assuming the text box is the
  specified width.