Android自动调整TextViews大小,然后减小字体大小 [英] Android autosizing TextViews split up words before decreasing font size

查看:417
本文介绍了Android自动调整TextViews大小,然后减小字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有办法避免吗?

如果我的文字是"Blablabla",并且它不适合正方形,则我不想输入类似的内容:

If my text is "Blablabla" and it doesn't fit in a square, I don't want to have something like:

Blabla- bla

Blabla- bla

我希望"Blablabla"具有较小的字体.有没有办法控制自动调整大小的TextView是否会拆分单词?

I want "Blablabla" with a smaller font size. Is there a way to control whether the autosizing TextView will split up words or not?

这是问题的一个例子:

那里的最小文字大小为1sp,因此很明显,该单词可以减小文字大小.

The minimum text size there is 1sp, so it's pretty clear the word could fit with a decreased text size.

看来这已经被报道了: https://issuetracker.google.com/issues/38468964

It seems this has been reported: https://issuetracker.google.com/issues/38468964

推荐答案

我过去实际上已经报告过此问题( 此处 此处 ,您已经找到了它),但似乎有解决方案,或者至少对我有用.

I've actually reported about this issue in the past (here and here, one you've already found out about), but it seems there is a solution, or at least it seems to work for me.

我认为该提示可能会有所帮助:

I think the tip could help:

https://developer.android.com/reference/android/widget/TextView#setBreakStrategy(int)

这意味着您可以为textView选择中断策略.示例:

This means you can choose the break strategy for the textView. Example:

        <TextView
            android:layout_width="250dp" android:layout_height="wrap_content" android:background="#f00"
            android:breakStrategy="balanced" android:hyphenationFrequency="none"
            android:text="This is an example text" android:textSize="30dp" app:autoSizeTextType="uniform"/>

可悲的是,这似乎并不总能正常工作.我已经注意到,在希伯来语中,它有时无法很好地传播:

Sadly, this doesn't always seem to work nicely as it should. I've noticed that on Hebrew, it sometimes doesn't get spread well:

https://issuetracker.google.com/issues/79936443

但是至少它不会无缘无故地散词.

But at least it won't put part-words for no reason.

使用此解决方案的主要缺点是,它只能从API 23中使用(根据 Android仪表板统计信息 ).有人要求它在支持库中( 此处 ) ,但被告知这是不可能的.

The major disadvantage of using this solution, is that it's available only from API 23 (at least 62% of the devices, according to Android dashboard statistics). Someone has asked it to be on the support library (here), but was told it's impossible.

这篇关于Android自动调整TextViews大小,然后减小字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆