I am taking data of variable sizes from the server and setting to a textView and i wanted the textview to resize according to the length of the text set.
It is given in
Revision 26.0.1 of Support Library added support for autosizing in AppCompatTextView.
Developers can now let the size of their text expand or contract automatically based on the size and characteristics of the TextView, making it much easier to optimize the text size on different screens or with dynamic content.
In Java:
Call the setAutoSizeTextTypeUniformWithConfiguration()
method:
setAutoSizeTextTypeUniformWithConfiguration(int autoSizeMinTextSize, int autoSizeMaxTextSize, int autoSizeStepGranularity, int unit)
In XML:
Use the autoSizeMinTextSize, autoSizeMaxTextSize, and autoSizeStepGranularity attributes to set the auto-sizing dimensions in the layout XML file:
In Java:
Call the setAutoSizeTextTypeUniformWithPresetSizes()
method:
setAutoSizeTextTypeUniformWithPresetSizes(int[] presetSizes, int unit)
In XML:
Use the autoSizePresetSizes attribute in the layout XML file:
To access the array as a resource, define the array in the res/values/arrays.xml file:
- 10sp
- 12sp
- 20sp
- 40sp
- 100sp