简体   繁体   English

如何在Android Studio中的TextView中自动调整文本大小?

[英]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. 您需要将TextView中的textSize设置为12sp或20sp。 Depending on your need 根据您的需要

For Textview with @+id/textView change height to android:layout_height="wrap_content" and android:layout_gravity="center" . 对于具有@+id/textView textView的Textview,将高度更改为android:layout_height="wrap_content"android:layout_gravity="center"

This will make Textview Flexible, Since its parent layout LinearLayout height is dependent on child view height. 这将使Textview灵活,因为其父布局LinearLayout高度取决于子视图的高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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