读书人

android编程中的琐屑知识点汇总(3)

发布时间: 2012-09-24 13:49:41 作者: rapoo

android编程中的琐碎知识点汇总(3)

1.图片加载方法,方便用户加载图片

public String[] StringFormat(String text, int maxWidth, int fontSize) {String[] result = null;Vector<String> tempR = new Vector<String>();int lines = 0;int len = text.length();int index0 = 0;int index1 = 0;boolean wrap;while (true) {int widthes = 0;wrap = false;for (index0 = index1; index1 < len; index1++) {if (text.charAt(index1) == '\n') {index1++;wrap = true;break;}widthes = fontSize + widthes;if (widthes > maxWidth) {break;}}lines++;if (wrap) {tempR.addElement(text.substring(index0, index1 - 1));} else {tempR.addElement(text.substring(index0, index1));}if (index1 >= len) {break;}}result = new String[lines];tempR.copyInto(result);return result;}

读书人网 >编程

热点推荐