android textview 竖排显示

来源:互联网 发布:数据开发 数据挖掘 编辑:程序博客网 时间:2024/04/28 16:08

在做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);}}


0 0
原创粉丝点击