Granularity
suggest changeIn 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:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/autosizing_textview_presetsize"
android:layout_width="wrap_content"
android:layout_height="250dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:autoSizeMaxTextSize="100sp"
android:autoSizeMinTextSize="12sp"
android:autoSizeStepGranularity="2sp"
android:autoSizeTextType="uniform"
android:text="Hello World!"
android:textSize="100sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
These android:autoSize* attributes require API 26. On earlier releases, use the matching app: attributes from AppCompat.
Check out the AutosizingTextViews-Demo at GitHub for more details.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents