自定义TextView实现竖排文本

文章介绍了在Android中实现竖排文本的三种方法,包括设置android:ems属性、自定义TextView绘制以及旋转TextView。每种方法都有其特点,如简单设置仅适用于中文,自定义绘制支持中英文但需更多代码,而旋转TextView则可能导致中文旋转问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近有竖排文本的需求,整理了一些实现方式,最终自定义TextView绘制文本方式满足需求。

参考文档:

https://blog.csdn.net/Blue_Tong/article/details/123376013

英文纵向显示-竖版TextView_windroid之父的博客-CSDN博客

1.设置 android:ems="1" 属性即可

<TextView
    android:text="我的应用"
    android:textSize="32sp"
    android:ems="1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

效果:显示中文

显示英文:


 

特点:

  • 实现简单
  • 无需自定义view
  • 英文不满足需求

2.自定义 TextView 继承 android TextView, 用画笔绘制


import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Path;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.Te
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值