android textview 竖排显示
16lz
2022-01-10
在做android开发时有时需要文字竖排显示,但是android自带的textview不支持,网上也没有提供好的解决办法,其实很简单了,只要对对原生textview进行简单自定义下就可以完美实现!请看源码。
package com.jingya.xiaochejingling.wight;import android.content.Context;import android.util.AttributeSet;import android.widget.TextView;public class TextViewVertical extends TextView {public TextViewVertical(Context context, AttributeSet attrs) {super(context, attrs);// TODO Auto-generated constructor stub}public TextViewVertical(Context context) {super(context);// TODO Auto-generated constructor stub}@Overridepublic void setText(CharSequence text, BufferType type) {// TODO Auto-generated method stubif ("".equals(text) || text == null || text.length() == 0) {return;}int m = text.length();StringBuffer sb = new StringBuffer();for (int i = 0; i < m; i++) {CharSequence index = text.toString().subSequence(i, i + 1);sb.append(index + "\n");}super.setText(sb, type);}}
更多相关文章
- 让android studio 支持Lambda
- Android(安卓)Vertical TextView 文字竖排
- cmd>>android
- cmd>>android
- cmd>>android
- Android(安卓)Studio 2.0 Preview发布,附下载地址,支持即时运行和
- Android项目Android(安卓)Studio目录结构
- android 常用代码备份
- android横屏竖屏处理