Use AutosizingTextView

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

What is AutosizingTextView?

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

Don't use 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.

Specify layout_width = "wrap_content" (bad example)

スクリーンショット 2017-10-31 14.32.45.png

It's going to be like this

Specify layout_height = "wrap_content" (bad example)

スクリーンショット 2017-10-31 14.33.09.png

Don't listen to me

Good example

スクリーンショット 2017-10-31 14.32.25.png

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.

スクリーンショット 2017-11-09 19.07.51.png

You have to read it properly

at the end

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!"

Recommended Posts

Use AutosizingTextView
Use before_action! !!
Use XMLHttpRequest
Use ActiveStorage!
Use JavaFX / TextFormatter
Use ControlsFX / Validation
Let's use jcmd
[Java] Use Collectors.collectingAndThen
[Rails] Use jQuery
Use sassc directly