I tried using AutosizingTextView. I was a little addicted to how to use it lightly, so I will summarize it as a commandment to myself. If you don't know it at all, you can use it as soon as you read this. ▷ Android Developer / Autosizing TextView
From Android O (API Level 26), you can use TextView that automatically adjusts the font size according to the layout size.
text_view.xml
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:autoSizeTextType="uniform" <!--Add this line-->
/>
If you want to use it with the default setting, you can add the above to TextView.
If you want to support versions earlier than API26
text_view_pre26.xml
<android.support.v7.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="200dp"
app:autoSizeTextType="uniform" <!--Add this line-->
/>
Let's use this.
Other usage is written in Android Developer, so I will omit it, but if there is demand, Japanese I will summarize it in.
Tips
wrap_content
If you put a fixed value in either width or height, will it work as if you could use the fixed value? I was thinking.
It's going to be like this
Don't listen to me
If you don't use wrap_content
, it works fine. Do not use wrap_content
when you want to autosize.
By the way, the link I posted was written properly.
You have to read it properly
As long as you specify the area, you can develop without worrying about the font size (sp), and you only have to worry about the margin when designing, so it seems to be easier.
Until recently, I didn't know that ʻandroid: singleLine` was deprecated (ignorance), and I wanted to put a constraint to fit it in one line. "Auto Sizing doesn't respond!"