1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問(wèn)題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
      怎么在Android中利用TextView調(diào)整文本內(nèi)容的字體大小

      這篇文章給大家介紹怎么在Android中利用TextView調(diào)整文本內(nèi)容的字體大小,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。

      專注于為中小企業(yè)提供網(wǎng)站設(shè)計(jì)制作、網(wǎng)站設(shè)計(jì)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)薊州免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上1000+企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。

      具體方法如下:

      /** 
       * 自定義TextView,文本內(nèi)容自動(dòng)調(diào)整字體大小以適應(yīng)TextView的大小 
       * @author yzp 
       */ 
      public class AutoFitTextView extends TextView { 
        private Paint mTextPaint; 
        private float mTextSize; 
        public AutoFitTextView(Context context) { 
          super(context); 
        } 
        public AutoFitTextView(Context context, AttributeSet attrs) { 
          super(context, attrs); 
        } 
        /** 
         * Re size the font so the specified text fits in the text box assuming the 
         * text box is the specified width. 
         * 
         * @param text 
         * @param textWidth 
         */ 
        private void refitText(String text, int textViewWidth) { 
          if (text == null || textViewWidth <= 0) 
            return; 
          mTextPaint = new Paint(); 
          mTextPaint.set(this.getPaint()); 
          int availableTextViewWidth = getWidth() - getPaddingLeft() - getPaddingRight(); 
          float[] charsWidthArr = new float[text.length()]; 
          Rect boundsRect = new Rect(); 
          mTextPaint.getTextBounds(text, 0, text.length(), boundsRect); 
          int textWidth = boundsRect.width(); 
          mTextSize = getTextSize(); 
          while (textWidth > availableTextViewWidth) { 
            mTextSize -= 1; 
            mTextPaint.setTextSize(mTextSize); 
            textWidth = mTextPaint.getTextWidths(text, charsWidthArr); 
          } 
          this.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize); 
        } 
        @Override 
        protected void onDraw(Canvas canvas) { 
          super.onDraw(canvas); 
          refitText(this.getText().toString(), this.getWidth()); 
        } 
      }

      關(guān)于怎么在Android中利用TextView調(diào)整文本內(nèi)容的字體大小就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。


      標(biāo)題名稱:怎么在Android中利用TextView調(diào)整文本內(nèi)容的字體大小
      本文URL:http://ef60e0e.cn/article/gedjhs.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        阿克陶县| 正宁县| 黄骅市| 长汀县| 吉林省| 资源县| 祁门县| 阳泉市| 桂东县| 方正县| 海宁市| 孝昌县| 元阳县| 凌源市| 丰原市| 临高县| 曲周县| 扬中市| 汪清县| 高青县| 大姚县| 宝坻区| 三明市| 新建县| 泽库县| 长寿区| 酒泉市| 白银市| 阳朔县| 通城县| 边坝县| 金坛市| 涡阳县| 新丰县| 澄江县| 乌鲁木齐市| 布尔津县| 商丘市| 福州市| 昌邑市| 陆丰市|