android 重新测量高度,android – StaticLayout高度测量关闭
我试图用字体
Latto-Reg绘制多行文本到位图,而StaticLayout似乎有问题.
paint.setTextSize(label.fontSize);
paint.setTypeface(face);
StaticLayout textLayout = new StaticLayout(label.text,paint,(int)StaticLayout.getDesiredWidth(label.text,paint),Alignment.ALIGN_NORMAL,1.0f,0.0f,false);
Bitmap bitmapAux = Bitmap.createBitmap(textLayout.getEllipsizedWidth(),textLayout.getHeight(),Bitmap.Config.ALPHA_8);
canvas.setBitmap(bitmapAux);
canvas.save();
canvas.translate(0,textLayout.height());
textLayout.draw(canvas);
canvas.restore();
纹理在顶部和底部有填充,具体取决于字体和大小,而文本完全适合位图,这是一个浪费的大量内存空间,并使其随机关闭.
我使用单线绘图测试,位图非常适合文本
paint.getTextBounds(label.text,label.text.length(),rect);
Bitmap bitmapAux = Bitmap.createBitmap(rect.width(),rect.height(),Bitmap.Config.ALPHA_8);
canvas.drawText(label.text,-rect.left,-rect.bottom,paint);
我试过从StaticLayout获取所有类型的指标,所有这些指标似乎都不在文本中:第0行界限,第0行顶部,最后一行底部……导致相同的填充问题.
编辑:
我通过使用基于偏移的单线绘图解决了这个问题. StillLayout类仍然使用几种不同的非标准字体绘制错误,我想知道原因.
更多推荐

所有评论(0)