diff --git a/DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/android/SpannedCacheStuffer.java b/DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/android/SpannedCacheStuffer.java index 29e909fd..4c0fc3b6 100644 --- a/DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/android/SpannedCacheStuffer.java +++ b/DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/android/SpannedCacheStuffer.java @@ -31,10 +31,7 @@ public void measure(BaseDanmaku danmaku, TextPaint paint) { text = new SpannedString(danmaku.text); } if (text != null) { - StaticLayout staticLayout = new StaticLayout(text, paint, (int) StaticLayout.getDesiredWidth(danmaku.text, paint), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true); - danmaku.paintWidth = staticLayout.getWidth(); - danmaku.paintHeight = staticLayout.getHeight(); - danmaku.obj = new SoftReference(staticLayout); + createStaticLayout(danmaku); return; } } @@ -57,8 +54,7 @@ public void drawText(BaseDanmaku danmaku, String lineText, Canvas canvas, float SoftReference reference = (SoftReference) danmaku.obj; StaticLayout staticLayout = reference.get(); if (staticLayout == null) { - super.drawText(danmaku, lineText, canvas, left, top, paint); - return; + createStaticLayout(danmaku); } boolean needRestore = false; if (left != 0 && top != 0) { @@ -77,4 +73,11 @@ public void clearCaches() { super.clearCaches(); System.gc(); } + + private void createAndMeasureStaticLayout(BaseDanmaku danmaku){ + StaticLayout staticLayout = new StaticLayout(text, paint, (int) StaticLayout.getDesiredWidth(danmaku.text, paint), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true); + danmaku.paintWidth = staticLayout.getWidth(); + danmaku.paintHeight = staticLayout.getHeight(); + danmaku.obj = new SoftReference(staticLayout); + } }