在做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
}
@Override
public void setText(CharSequence text, BufferType type) {
// TODO Auto-generated method stub
if ("".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);
}
}