简体   繁体   English

Android-调整文本大小以适合TextView

[英]Android - Resize Text to fit inside a TextView

I'm trying to resize the wrapping text in a TextView to fit within its bounds. 我正在尝试调整TextView换行文本的大小以适合其范围。 I've created a new class with the source from here and I've added it inside my layout: 我从这里创建了一个带有源代码的新类,并将其添加到布局中:

            <com.util.AutoResizeTextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginLeft="10dp"
                android:layout_alignLeft="@id/ivBulb"
                android:layout_marginTop="5dp"
                android:layout_marginBottom="80dp"
                android:layout_below="@id/ivBulb"
                android:layout_marginRight="10dp"
                android:id="@+id/textP"
                android:ellipsize="none"
                android:fontFamily="sans-serif"
                android:textColor="#000"
                android:textSize="100sp"/> <!--maximum size -->

The text that should be displayed inside the TextView is something like: 应该在TextView内部显示的文本是这样的:

The sunset filled the entire sky with the deep color of rubies, setting the clouds ablaze. The waves crashed and danced along the shore, moving up and down in a graceful and gentle rhythm like they were dancing.

Some texts can be a multiline but some don't. 有些文本可以是多行,但有些则不能。 My problem is that the text font size is small (about 35dp) and it's always the same :( I've added a ScrollView in order to be able to display all the text but I want to keep just the TextView and the text to resize 我的问题是文本字体大小很小(大约35dp),并且总是相同的:(我添加了ScrollView以便能够显示所有文本,但是我只想保留TextView和要调整大小的文本

I'm new in Android development so please be gentle. 我是Android开发的新手,请保持谦虚。

use from android.support.v7.widget.AppCompatTextView and set android.support.v7.widget.AppCompatTextView使用并设置

android:ellipsize="none"
                                android:singleLine="true"
                                app:autoSizeMaxTextSize="14sp"
                                app:autoSizeMinTextSize="12sp"
                                app:autoSizeStepGranularity="0.5sp"
                                app:autoSizeTextType="uniform"

in

<android.support.v7.widget.AppCompatTextView
                                android:ellipsize="none"
                                android:singleLine="true"
                                app:autoSizeMaxTextSize="14sp"
                                app:autoSizeMinTextSize="12sp"
                                app:autoSizeStepGranularity="0.5sp"
                                app:autoSizeTextType="uniform"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"              android:id="@+id/txt_ortopedi" 
                                android:textColor="@color/text_color"
                                android:padding="4dp" android:hint="@string/search"
                                android:gravity="clip_vertical|center_horizontal" android:layout_gravity="center"
                                android:background="@color/white"/>

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

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