1、优化直播间聊天换行问题

2、PK连麦 结束图标(英文)更换
This commit is contained in:
老皮 2024-10-15 18:30:10 +08:00
parent 151abf13e8
commit 95128b64ea
2 changed files with 21 additions and 16 deletions

View File

@ -381,7 +381,7 @@
<string name="live_follow_anchor">has followed the anchor</string>
<string name="live_report">Are you sure to report?</string>
<string name="live_link_mic_2">Interaction</string>
<string name="live_link_mic_3">Quit even wheat</string>
<string name="live_link_mic_3">End mic</string>
<string name="live_link_mic_4">Allowed even wheat</string>
<string name="live_link_mic_5">Ban Lian Mai</string>
<string name="link_mic_wait">Initiate a link request</string>

View File

@ -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;