-1

I have a textview and the text is loaded dynamically.

 <TextView
            android:id="@+id/txt_song_title"
            style="?attr/txtcolorHightlight"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_alignTop="@id/frlyt_img_cover"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginTop="@dimen/activity_vertical_margin"
            android:layout_toLeftOf="@id/img_audio_source_icon"
            android:ellipsize="end"
            android:fontFamily="@string/roboto_light"
            android:maxLines="3"
            android:text=""
            android:textSize="@dimen/font_36" />

The textview has to show the entire text which is set (10 to 100+)characters. Based on text length, the font size should be changed inorder to fit the entire text. How to calculate num of words in the textview to change font size and display entire text without clipping dynamically?

Shalini
  • 151
  • 1
  • 2
  • 9
  • possible duplicate of [how to count the exact number of words in a string that has empty spaces between words?](http://stackoverflow.com/questions/8924599/how-to-count-the-exact-number-of-words-in-a-string-that-has-empty-spaces-between) – 2Dee Jan 29 '15 at 10:01

2 Answers2

1

I think you can do it from java code level. TextView class provides methods to implement this.

Following link may be useful.

Auto Scale TextView Text to Fit within Bounds

Community
  • 1
  • 1
0

Try using a library, for example a simple google search gave me this: https://github.com/grantland/android-autofittextview

I have not tried it but it seems ok :)

Evripidis Drakos
  • 852
  • 1
  • 7
  • 15