0

I finally found the code to resize the text based on the height of the textview.Source, but i am not getting how to pass the text in this function,my text is cmoing from another intent

public int getHeightOfMultiLineText(String text,int textSize, int maxWidth) {
        TextPaint paint = new TextPaint();
        paint.setTextSize(textSize);
        int index = 0;
        int linecount = 0;
        while(index < text.length()) {
            index += paint.breakText(text,index,text.length(),true,maxWidth,null);
            linecount++;
        }

        Rect bounds = new Rect();
        paint.getTextBounds("Yy", 0, 2, bounds);
        // obtain space between lines
        double lineSpacing = Math.max(0,((linecount - 1) * bounds.height()*0.25)); 

        return (int)Math.floor(lineSpacing + linecount * bounds.height());

    }
Community
  • 1
  • 1
user2451541
  • 71
  • 3
  • 12

1 Answers1

0

Well you can get the text of TextView as String using urTextView.getText().toString()

TextView urTextView;
String text = urTextView.getText().toString();

int textSize = 100;
int maxHeight = 50;
while(getHeightOfMultiLineText(text,textSize,maxWidth) > maxHeight)
    textSize--;

This should work.

Ankit Aggarwal
  • 2,367
  • 24
  • 30