赞
踩
因为要做一个竖着显示文字的TextView,然后就在网上找了找,都是说用一个LinearLayout来垂直排列多个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);
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。