您的位置:首页 > 移动开发 > Android开发

Android TextVIew 文字横向竖排

2017-07-02 13:32 274 查看
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++)  

            {  

//                System.out.println("什么情况------"+text);  

                TextView oneText=new TextView(context);  

                oneText.setTextColor(color);   

                oneText.setText(text.substring(i, i+1));  

                if(size>0)  

                {  

                    oneText.setTextSize(size);  

                }  

                addView(oneText);  

            }  

        }  

    }  

    public void setTextColor(int color)  

    {  

        this.color=color;  

    }  

    public void setTextSize(int size)  

    {  

        this.size=size;  

    }  

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Android TextVIew 文字横