竖排文字

This commit is contained in:
zengfantian 2015-04-06 23:38:44 +08:00
parent bb3bbdc954
commit d89a154f5a
1 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,62 @@
package com.zftlive.android.view;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.TextView;
/**
* 竖着添加TextView方式实现竖排文字
* @author 曾繁添
* @version 1.0
*
*/
public class VerticalTextView extends LinearLayout {
private String text;
private Context context;
private int color;
private int size;
public VerticalTextView(Context context) {
super(context);
setOrientation(VERTICAL);
this.context = context;
}
public VerticalTextView(Context context, AttributeSet attrs) {
super(context, attrs);
setOrientation(VERTICAL);
this.context = context;
}
public void setText(String text) {
this.text = text;
addText();
}
private void addText() {
removeAllViews();
if (text != null) {
char[] chara = text.toCharArray();
for (int i = 0; i < chara.length; i++) {
TextView item = new TextView(context);
item.setTextColor(color);
item.setText(chara[i]);
if (size > 0) {
item.setTextSize(size);
}
addView(item);
}
}
}
public void setTextColor(int color) {
this.color = color;
}
public void setTextSize(int size) {
this.size = size;
}
}