1. 程式人生 > >android 動態改變字型大小

android 動態改變字型大小


/** 動態計算字型大小

* @param  WriteSize  預設字型大小50
* @param Texts 列印字串List
* @param WriteHeight 列印區域高度
* @param writeWidth  列印區域寬度
* @return
*/
public static int FontSize(List<String> Texts,int WriteHeight, int writeWidth) {


Paint paint = new Paint();
paint.setStrokeWidth(3.0f);
int WriteSize = 50;
int WlenHeight = 0;
List<String> listLen1;


while (true) {
int Wlen1 = 0;
paint.setTextSize(WriteSize);
for (int i = 0; i < Texts.size(); i++) {
listLen1 = StringUtil
.autoSplit(Texts.get(i), paint, writeWidth);
Wlen1 += listLen1.size();
}


WlenHeight = Wlen1 * WriteSize;
if (WlenHeight > WriteHeight)
WriteSize -= 1;
else
break;
}
return WriteSize;
}