如何在 Android Studio 的 TextView 中自动调整文本大小?
how to auto resize text in TextView in Android Studio?
我正在尝试制作一个灵活的文本,我尝试了一些类似 unform 的方法,但它不起作用。
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>
我正在尝试制作灵活的文本,我尝试了一些类似 unform 的方法,但它不起作用。
我正在尝试制作一个灵活的文本,我尝试了一些类似 unform 的东西,但它没有 work.i我试图制作一个灵活的文本,我尝试了一些类似 unform 的东西,但它没有 work.i'我试图制作一个灵活的文本,我尝试了一些类似 unform 的东西,但它没有 work.i我试图制作一个灵活的文本,我尝试了一些像 unform 的东西,但它没有 work.i正在尝试为了制作灵活的文本,我尝试了一些类似 unform 的东西,但它没有 work.i我试图制作一个灵活的文本,我尝试了一些类似 unform 的东西,但它不起作用。
您需要修复 layout_width 或 layout_height 才能使自动调整文本大小 属性 正常工作。
您需要将 TextView 中的 textSize 设置为 12sp 或 20sp 之类的值。根据您的需要
对于具有 @+id/textView
的 Textview,将高度更改为 android:layout_height="wrap_content"
和 android:layout_gravity="center"
。
这将使 Textview 灵活,因为它的父布局 LinearLayout
高度取决于子视图高度。
我正在尝试制作一个灵活的文本,我尝试了一些类似 unform 的方法,但它不起作用。
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>
我正在尝试制作灵活的文本,我尝试了一些类似 unform 的方法,但它不起作用。 我正在尝试制作一个灵活的文本,我尝试了一些类似 unform 的东西,但它没有 work.i我试图制作一个灵活的文本,我尝试了一些类似 unform 的东西,但它没有 work.i'我试图制作一个灵活的文本,我尝试了一些类似 unform 的东西,但它没有 work.i我试图制作一个灵活的文本,我尝试了一些像 unform 的东西,但它没有 work.i正在尝试为了制作灵活的文本,我尝试了一些类似 unform 的东西,但它没有 work.i我试图制作一个灵活的文本,我尝试了一些类似 unform 的东西,但它不起作用。
您需要修复 layout_width 或 layout_height 才能使自动调整文本大小 属性 正常工作。
您需要将 TextView 中的 textSize 设置为 12sp 或 20sp 之类的值。根据您的需要
对于具有 @+id/textView
的 Textview,将高度更改为 android:layout_height="wrap_content"
和 android:layout_gravity="center"
。
这将使 Textview 灵活,因为它的父布局 LinearLayout
高度取决于子视图高度。