From 95128b64eac1cc0f9e2d0df03ca2606c3e571a74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=81=E7=9A=AE?= <14840170+lao-pi123@user.noreply.gitee.com> Date: Tue, 15 Oct 2024 18:30:10 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BC=98=E5=8C=96=E7=9B=B4=E6=92=AD?= =?UTF-8?q?=E9=97=B4=E8=81=8A=E5=A4=A9=E6=8D=A2=E8=A1=8C=E9=97=AE=E9=A2=98?= =?UTF-8?q?=202=E3=80=81PK=E8=BF=9E=E9=BA=A6=20=E7=BB=93=E6=9D=9F=E5=9B=BE?= =?UTF-8?q?=E6=A0=87=EF=BC=88=E8=8B=B1=E6=96=87=EF=BC=89=E6=9B=B4=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/src/main/res/values/strings.xml | 2 +- .../com/yunbao/live/utils/LiveTextRender.java | 35 +++++++++++-------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index f00d4c185..7018958cf 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -381,7 +381,7 @@ has followed the anchor Are you sure to report? Interaction - Quit even wheat + End mic Allowed even wheat Ban Lian Mai Initiate a link request diff --git a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java index 81bf31316..00e0252d0 100644 --- a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java +++ b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java @@ -949,6 +949,8 @@ public class LiveTextRender { // availableWidth textView 可用宽度 prefixWidth 图片宽度 int availableWidth = textView.getWidth() - textView.getPaddingLeft() - textView.getPaddingRight(); // Log.e("renderChatNew", "availableWidth: " + availableWidth); +// Log.e("renderChatNew", "textView.getPaddingLeft(): " + textView.getPaddingLeft()); +// Log.e("renderChatNew", "textView.getPaddingRight(): " + textView.getPaddingRight()); StringBuilder sb = new StringBuilder(); String name = bean.getUserNiceName(); @@ -966,22 +968,25 @@ public class LiveTextRender { if (nameWidth + prefixWidth > availableWidth) { StringBuilder sb_tmp = new StringBuilder(); + StringBuilder saveContentSB = new StringBuilder(); int initImageWidth = prefixWidth; for (int i = 0; i < sb.length(); i++) { char content = sb.charAt(i); sb_tmp.append(content); - float measuredText = paint.measureText(sb_tmp.toString()) + initImageWidth; -// Log.e("renderChatNew", "measuredText: " + measuredText + " availableWidth: " + availableWidth); - if (measuredText > availableWidth) { + float measuredTextWidth = paint.measureText(sb_tmp.toString()) + initImageWidth; +// Log.e("renderChatNew", "文字:" + sb_tmp.toString() + " measuredTextWidth: " + measuredTextWidth + " initImageWidth:" + initImageWidth + " availableWidth: " + availableWidth); + if (measuredTextWidth > availableWidth) { initImageWidth = 0; - sb_tmp.deleteCharAt(sb_tmp.length() - 1); - sb_tmp.append("\n"); - sb_tmp.append(content); + saveContentSB.append("\n"); // Log.e("renderChatNew", "sb_tmp.toString():" + sb_tmp.toString()); + sb_tmp.setLength(0); + sb_tmp.append(content); } + saveContentSB.append(content); +// Log.e("renderChatNew", "saveContentSB.toString():" + saveContentSB.toString()); } - builder.append(sb_tmp); + builder.append(saveContentSB); // Log.e("renderChatNew", "builder.toString():" + builder.toString()); } else { @@ -1030,25 +1035,25 @@ public class LiveTextRender { } SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(name); - float measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + float measuredTextWidth = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; // Rect mRect = new Rect(); // textView.getPaint().getTextBounds(sb.toString(), 0, sb.length(), mRect); int width = (int) (((ViewGroup) textView.getParent()).getMeasuredWidth() - prefixEmpty); String TAG = "文字渲染"; - // Log.i(TAG, "测算|" + measuredText + "|" + mRect.width() + "|" + sb.toString()); + // Log.i(TAG, "测算|" + measuredTextWidth + "|" + mRect.width() + "|" + sb.toString()); //|810|810|810|786|786 // Log.i(TAG, "控件宽度|" + width + "|" + ((ViewGroup) textView.getParent()).getWidth() + "|" + ((ViewGroup) textView.getParent()).getMeasuredWidth() + "|" + textView.getWidth() + "|" + textView.getMeasuredWidth()); // Log.i(TAG, "前缀预留宽度|" + prefixWidth + "|" + prefixEmpty); // Log.i(TAG, "renderChat: " + textView.getCompoundPaddingLeft() + "|" + textView.getCompoundPaddingRight() + "|"); //检测渲染后图标+名字是否超过父布局宽度,超过了就做换行处理 String prefixName = ""; - if (measuredText > width) { + if (measuredTextWidth > width) { sb.clear(); for (int i = 0; i < name.length(); i++) { sb.append(name.charAt(i)); - measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; - Log.i(TAG, i + "逐测算|" + measuredText + "|" + textTemp); - if (measuredText > width) { + measuredTextWidth = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + Log.i(TAG, i + "逐测算|" + measuredTextWidth + "|" + textTemp); + if (measuredTextWidth > width) { prefixName = name.substring(0, i + textTemp); name = prefixName + "\n" + name.substring(i + textTemp); break; @@ -1079,12 +1084,12 @@ public class LiveTextRender { Log.i(TAG, "renderChat: " + content); sb.append(name).append(content); SpannableStringBuilder csb = null; - measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + measuredTextWidth = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; sb.clear(); sb.append(prefixName); prefixEmpty = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; StringBuilder stringBuilder = new StringBuilder(); - if (measuredText > width) { + if (measuredTextWidth > width) { sb.clear(); sb.append(name); float lineWidth = 0;