简体   繁体   中英

AutoSizeTextType uniform crops my textview bottom part

I have such code for textview:

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="sometextsometextsometextsometextsometextsometextsometextsometextsometext"
android:textStyle="bold"
app:autoSizeMaxTextSize="30sp"
app:autoSizeMinTextSize="18sp"
app:autoSizeStepGranularity="2sp"
app:autoSizeTextType="uniform"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>

and it looks on the design:

在此处输入图像描述

after some tests I found that when I remove app:autoSizeTextType="uniform" or change it to none my text can fill TextView without cropping. But as I know app:autoSizeTextType="none" turns off responsive text size. Maybe I did any mistake in my xml what causes such problem?

There are multiple solutions of this problem but below solution might be useful for you.

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
    android:id="@+id/t1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:autoSizeMinTextSize="18sp"
    android:padding="10dp"
    android:minLines="2"
android:text="sometextsometextsometextsometextsometextsometextsometext"
    android:background="#faa"
    android:textStyle="bold"
    app:autoSizeMaxTextSize="30sp"
    app:autoSizeTextType="uniform"
    app:autoSizeStepGranularity="2sp"
    app:layout_constraintBottom_toTopOf="@id/horizontalGuideline"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<androidx.constraintlayout.widget.Guideline
    android:id="@+id/horizontalGuideline"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    app:layout_constraintGuide_percent="0.1"/>
</androidx.constraintlayout.widget.ConstraintLayout>

Here you can change the Guideline percent according to your requirement, in this example I have kept 0.1 which is 10% from top of the page.

I hope it will resolve your issue. Github code link: https://github.com/parmeshtoyou/StackOverflow/blob/master/app/src/main/res/layout/activity_main2.xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM