Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autosizing TextViews for labels #16

Open
ElyDantas opened this issue Jun 19, 2020 · 0 comments
Open

Autosizing TextViews for labels #16

ElyDantas opened this issue Jun 19, 2020 · 0 comments

Comments

@ElyDantas
Copy link

Autosizing TextViews

With Android 8.0 (API level 26) and higher, you can instruct a TextView to let the text size expand or contract automatically to fill its layout based on the TextView's characteristics and boundaries. This setting makes it easier to optimize the text size on different screens with dynamic content.

The Support Library 26.0 provides full support to the autosizing TextView feature on devices running Android versions prior to Android 8.0 (API level 26). The library provides support to Android 4.0 (API level 14) and higher. The android.support.v4.widget package contains the TextViewCompat class to access features in a backward-compatible fashion.

To define the default setting in XML through the support library, use the app namespace and set the autoSizeTextType attribute to none or uniform.

Making every TextView label align to it's rating bar's top and bottom and using AutoSizeText attributes we can make it not only backwards compatible but auto resizable, without the need to set some static value for bar:text_size:

<TextView
    android:id="@+id/label"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_alignTop="@+id/bar"
    android:layout_alignBottom="@+id/bar"
    app:autoSizeTextType="uniform"
    app:autoSizeMinTextSize="1sp"
    app:autoSizeMaxTextSize="112sp"
    app:autoSizeStepGranularity="1sp" />

Preventing a behaviour like this:

ratingBar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant