android竖排TextView(字是横向的)
16lz
2021-01-26
package com.haishidaxue.ding.testcreateandroidproject.widget;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.TextView;
/**
* Created by apple on 16/3/9.
*/
public class VerticalTextView extends LinearLayout {
public VerticalTextView(Context context, AttributeSet attrs) {
super(context, attrs);
setOrientation(VERTICAL);
this.context = context;
}
private String text;
private Context context;
private int color;
private int size;
public VerticalTextView(Context context) {
super(context);
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 oneText = new TextView(context);
oneText.setTextColor(color);
oneText.setText(text.substring(i, i + 1));
addView(oneText);
}
}
}
public void setTextColor(int color) {
this.color = color;
}
public void setTextSize(int size) {
this.size = size;
}
}
import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.TextView;
/**
* Created by apple on 16/3/9.
*/
public class VerticalTextView extends LinearLayout {
public VerticalTextView(Context context, AttributeSet attrs) {
super(context, attrs);
setOrientation(VERTICAL);
this.context = context;
}
private String text;
private Context context;
private int color;
private int size;
public VerticalTextView(Context context) {
super(context);
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 oneText = new TextView(context);
oneText.setTextColor(color);
oneText.setText(text.substring(i, i + 1));
addView(oneText);
}
}
}
public void setTextColor(int color) {
this.color = color;
}
public void setTextSize(int size) {
this.size = size;
}
}
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer