Auto Scale TextView Text to Fit within Bounds

后端 未结 30 3454
囚心锁ツ
囚心锁ツ 2020-11-21 05:49

I\'m looking for an optimal way to resize wrapping text in a TextView so that it will fit within its getHeight and getWidth bounds. I\'m not simply looking for

30条回答
  •  梦如初夏
    2020-11-21 06:13

    I have use code from chase and M-WaJeEh and I found some advantage & disadvantage here

    from chase

    Advantage:

    • it's perfect for 1 line TextView

    Disadvantage:

    • if it's more than 1 line with custom font some of text will disappear

    • if it's enable ellipse, it didn't prepare space for ellipse

    • if it's custom font (typeface), it didn't support

    from M-WaJeEh

    Advantage:

    • it's perfect for multi-line

    Disadvantage:

    • if set height as wrap-content, this code will start from minimum size and it will reduce to smallest as it can, not from the setSize and reduce by the limited width

    • if it's custom font (typeface), it didn't support

提交回复
热议问题