How to adjust text font size to fit textview

后端 未结 22 1776
無奈伤痛
無奈伤痛 2020-11-22 05:15

Is there any way in android to adjust the textsize in a textview to fit the space it occupies?

E.g. I\'m using a TableLayout and adding several Te

22条回答
  •  再見小時候
    2020-11-22 06:08

    I don't known this is correct way or not bt its working ...take your view and check OnGlobalLayoutListener() and get textview linecount then set textSize.

     yourView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                if (textView.getLineCount()>=3) {
                    textView.setTextSize(20);
                }else{
                    //add somthing
                  }
            }
        });
    

    Its very simple few line code..

提交回复
热议问题