简体   繁体   中英

how to auto resize text in TextView in Android Studio?

i'm trying to make a flexible text, i tried some thing like unform but it doest not work.

explaining image error

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/MainRealative"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context=".CalculatingPage"
                tools:layout_editor_absoluteY="25dp" android:background="@drawable/fneclis_sky_bg">


    <android.support.v7.widget.RecyclerView
            android:id="@+id/rvCalPage"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/CL"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/textViewSPECIALITY"
            android:paddingTop="8dp"
            android:visibility="visible"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

    </android.support.v7.widget.RecyclerView>

    <TextView
            android:id="@+id/textViewSPECIALITY"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:background="@drawable/header_rounded_down"
            android:gravity="center"
            android:padding="6dp"
            android:text="@string/threePTS"
            android:textColor="@color/White"
            android:visibility="visible"
            app:layout_constrainedHeight="false"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:textSize="18sp" app:fontFamily="@font/vipraw" android:textStyle="bold"/>

    <LinearLayout
            android:id="@+id/relativeLayoutTxtView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="@color/blueTHREE"
            android:gravity="center"
            android:orientation="horizontal" android:visibility="gone">

        <Button
                android:id="@+id/cal_btn1"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_margin="6dp"
                android:background="@drawable/calculator"
                android:textColor="@color/White"/>

        <TextView
                android:id="@+id/textView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="@string/threePTS"
                android:textColor="@color/White"
                android:visibility="gone"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                android:paddingEnd="2dp" tools:ignore="RtlSymmetry" tools:targetApi="o"
                android:textSize="28sp" android:padding="4dp" android:paddingRight="2dp"/>

    </LinearLayout>
    <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" android:id="@+id/CL" android:layout_alignParentBottom="true">

        <LinearLayout
                android:id="@+id/relativeLayoutTxtView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:background="@color/blueTHREE"
                android:gravity="center"
                android:orientation="horizontal" android:visibility="gone"
                app:layout_constraintBottom_toBottomOf="@+id/tapBarMenu"
                tools:layout_editor_absoluteX="0dp"
        >

            <Button
                    android:id="@+id/cal_btn"
                    android:layout_width="76dp"
                    android:layout_height="76dp"
                    android:layout_margin="6dp"
                    android:background="@drawable/calculator"
                    android:textColor="@color/White"/>

            <TextView
                    android:id="@+id/textView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:text="@string/threePTS"
                    android:textColor="@color/White"
                    android:visibility="gone"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    android:paddingEnd="2dp" tools:ignore="RtlSymmetry" tools:targetApi="o"
                    android:textSize="28sp" android:padding="4dp" android:paddingRight="2dp"/>

        </LinearLayout>
        <com.michaldrabik.tapbarmenulib.TapBarMenu
                android:id="@+id/tapBarMenu"
                android:layout_width="match_parent"
                app:tbm_buttonSize="76dp"
                android:layout_height="80dp"
                android:layout_gravity="bottom"
                app:tbm_backgroundColor="@color/blueTHREE"
                app:tbm_iconClosed="@drawable/calculator"
                app:tbm_menuAnchor="bottom"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                android:background="@color/transWhite" app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintVertical_bias="1.0">
        </com.michaldrabik.tapbarmenulib.TapBarMenu>
    </android.support.constraint.ConstraintLayout>
</RelativeLayout>

i'm trying to make a flexible text, i tried some thing like unform but it doest not work. i'm trying to make a flexible text, i tried some thing like unform but it doest not work.i'm trying to make a flexible text, i tried some thing like unform but it doest not work.i'm trying to make a flexible text, i tried some thing like unform but it doest not work.i'm trying to make a flexible text, i tried some thing like unform but it doest not work.i'm trying to make a flexible text, i tried some thing like unform but it doest not work.i'm trying to make a flexible text, i tried some thing like unform but it doest not work.

您需要固定layout_width或layout_height才能使自动文本大小调整属性起作用。

You need to set textSize in TextView to something like 12sp or 20sp. Depending on your need

For Textview with @+id/textView change height to android:layout_height="wrap_content" and android:layout_gravity="center" .

This will make Textview Flexible, Since its parent layout LinearLayout height is dependent on child view height.

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