Android 13 新的换行策略和针对日文的优化

Android13为TextView引入了新的换行策略和日文短语换行策略,提供了更好的文本布局和阅读体验。开发者可以通过LineBreakConfig动态设置lineBreakStyle和lineBreakWordStyle,影响文本换行规则。在日语环境下,短语换行策略可优化阅读连贯性,且性能影响微乎其微。适配时需注意布局和已有换行设置,确保兼容性。

前言

Android 13 向 TextView 控件引入了新的换行策略,同时针对日文提供了换行优化。系统将依据开发者指定的换行策略、日文短语换行策略进行文本换行。这将促使文本内容不再杂乱无章、更加具有层次、便于阅读。

下面我们从 API、实战、适配办法等多个角度来快速学习一下这个新特性。

换行策略 lineBreakStyle

Indicates the line break strategies can be used when calculating the text wrapping.

Constant Value Description
none 0 No line break style specific.
loose 1 Use the least restrictive rule for line-breaking.
normal 2 Indicate breaking text with the most comment set of line-breaking rules.
strict 3 ndicates breaking text with the most strictest line-breaking rules.

事实上来自于 CSSline-break 属性,主要是针对 CJK 语言,也就是中日韩 3 种语言提供的换行规则。

Android 提供的属性和 CSS 的略有差异,但 loosenormalstrict 这三个属性进行了保留,后面将通过 DEMO 进行属性表现上的差异说明。

短语换行策略 lineBreakWordStyle

Specify the phrase-based line break can be used when calculating the text wrapping.

Constant Value Description
none 0 No line break word style specific.
phrase 1 Specify the phrase based breaking.

默认不生效,设置为 phrase 则生效。

动态设置

除了上述属性以外,TextView 理所应当地提供了 setLineBreakConfig() 来动态更新换行策略。

public void setLineBreakConfig (LineBreakConfig lineBreakConfig)
Parameters
lineBreakConfig LineBreakConfig: the line break config for text wrapping. This value cannot be null.
LineBreakConfig

Android 13 新引入的承载换行策略的配置类,提供了上述属性相对应的常量以及返回策略所必要的 get 方法。

Constants
int LINE_BREAK_STYLE_LOOSEUse the least restrictive rule for line-breaking.
int LINE_BREAK_STYLE_NONENo line break style specified.
int LINE_BREAK_STYLE_NORMALIndicate breaking text with the most comment set of line-breaking rules.
int<
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

TechMerger

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值