当前位置:   article > 正文

Android 竖排的TextView_安卓纵向text

安卓纵向text

因为要做一个竖着显示文字的TextView,然后就在网上找了找,都是说用一个LinearLayout来垂直排列多个TextView,我就觉得这样的话如果有很多文字的话,就会造成性能上的影响,所以我就按照自己的思路来。

  • 找到TextView的写入内容的方法
  • 重写该方法
  • 在内容写入之前我们把内容跨行竖着输入进去

按照这个思路来,找到我们经常使用的setText()。

全部代码

public class VerticalButton extends android.support.v7.widget.AppCompatButton{


    public VerticalButton(Context context) {
        super(context);
    }

    public VerticalButton(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public VerticalButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void setText(CharSequence text, BufferType type) {
        StringBuffer sb=new StringBuffer();
        for (int i = 0; i < text.length(); i++) {
            sb.append(text.charAt(i));
            if (i<text.length()-1){
                sb.append("\n");
            }

        }
        super.setText(sb.toString(), type);
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号