想写一个“手持字幕屏幕”,即可以打字(尽量的大文字)给人看,我用的是:StaticLayout类在while (true){}中不断调用
现在想在输入时自动调整文字大小 我是if大 就减小if小就增大,这样会产生反复调整大小,没完没了的抖动,我现在暂时通过限制调整时间在9秒之内,勉强能用。
但肯定不是好办法
以下是主要实现代码:
private float g_resetTextSize;
private TextPaint g_textPaint;
private void drawString(Canvas p_canvasLocked){
if (p_canvasLocked != null) {
p_canvasLocked.rotate(90);// 字体旋转9度
float l_left = 0;// l_centerX;
float l_top = - Config.deviceHeight/2;
float l_marging = 20;
g_textPaint.setColor(Color.parseColor("#000000"));
g_textPaint.setTextSize(g_resetTextSize);
g_textPaint.setAntiAlias(true);
StaticLayout l_layoutopen =new StaticLayout(Config.ShowTextMsg, g_textPaint, p_canvasLocked.getHeight(),
Layout.Alignment.ALIGN_CENTER,1.0f,0.0f , true);
// //超过Config.deviceHeight屏幕时,就会换行,也可以使用“\r\n”来实现换行
//Log.i(Config.myTag, "p_canvasLocked.getHeight(): "+p_canvasLocked.getHeight());//3040
int l_height = l_layoutopen.getHeight();
if (Config.isReadjust){
if((l_height - Config.deviceWidth) > l_marging ){//总行高度 大于屏幕宽度
g_resetTextSize -= 5; //字体太大了需要减小
}
else if ((l_height - Config.deviceWidth) < l_marging ){
g_resetTextSize += 5;
}
}
p_canvasLocked.save();
p_canvasLocked.translate(l_left+l_marging,l_top+l_marging);
l_layoutopen.draw(p_canvasLocked);
p_canvasLocked.restore();
}
//return g_resetTextSize;
}