I don't want to use scrollView.The behavior I want is this:
Short Text:
Long text:
On
Try this:
<TextView
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="Your text here"
android:textColor="@color/purple_500"
android:textStyle="bold"
android:lines="2"
android:gravity="center"
android:autoSizeTextType="uniform"
android:autoSizeMinTextSize="16sp"
android:autoSizeMaxTextSize="100sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
For short text your output be like:
For long text:
Have you tried minLines in XML?
something like this:
this should work fine for you if you always have at least two words (or the minimal amount of lines you've set in the XML)...
If this isn't what you search for, maybe you could handle it programmatically and set the width and height of the TextView according to the number of words... not the exact method, but for example:
You write it your way, you know your needs...
And, there's also this answer, that I'm actually not familiar with but might also answer your needs...
UPDATE
In case I didn't understand when I wrote the above and you want the
TextViewto have maxLines and only dynamic width, you could use thetv.setWidth(t.length * [bla bla bla]);in the semi method that I wrote above, and in the .XML use maxLines...Also, next time please give a bit more specific questions so people won't have to struggle to try to understand how to give you the relevant answer to what you want.
I hope it helps you!