

They do, of course, affect the text layout bounds and thus impact the automatic size chosen for the text. letterSpacing, lineHeight, etc.) are not changed. Auto-sizing (as the name would suggest) only adjusts the text size.Note: All of the examples in this post will use the AndroidX implementation.īefore we get going, there are two important points to keep in mind: Use the functions in TextViewCompat instead those on TextView directly.Use the app namespace for XML attributes.The differences to the framework API are minimal: Thankfully, all of the auto-sizing functionality is available in the AndroidX core package (formerly Support Library). There are three distinct ways of enabling auto-sizing on a TextView, with increasing levels of specificity: Default, Granular and Preset.Īt the time of this writing, the chances of anyone having a minSdk of 26 are quite slim. It can be implemented in XML layouts or programmatically. The TextView auto-sizing API is fairly concise. In these scenarios, TextView auto-sizing is precisely what we need. The text can’t scroll and we can’t just add a "read more" button. Examples include a newspaper-style layout, a font selector that needs to show each different font typeface/name on a single-line, etc. However, consider the case where the width and/or height of the text bounds are fixed and the text needs to adapt to the available space.

LETTERSPACE APP ANDROID ANDROID
When is this needed? 🤔įor Android Development, using a fixed textSize, layout_width="match_parent” and layout_height="wrap_content” (perhaps inside a scrollable parent) is fairly common practice and suitable for most TextView use cases. It offers a simple yet powerful API to solve a particular problem: scaling of text size to fit text bounds. TextView auto-sizing was introduced to the framework with Android 8.0 Oreo (API 26).
