战令相关UI调整

This commit is contained in:
2024-01-26 13:42:38 +08:00
parent 0552f56eb4
commit f99641ed35
13 changed files with 521 additions and 367 deletions

View File

@@ -0,0 +1,105 @@
package com.yunbao.common.views;
import android.content.Context;
import android.graphics.Paint;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.ViewTreeObserver;
import android.widget.TextView;
import com.yunbao.common.utils.StringUtil;
public class AutoSplitTextView extends androidx.appcompat.widget.AppCompatTextView {
private boolean mEnabled = true;
public AutoSplitTextView(Context context) {
super(context);
}
public AutoSplitTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AutoSplitTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public void setAutoSplitEnabled(boolean enabled) {
mEnabled = enabled;
}
/* @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY
&& MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.EXACTLY
&& getWidth() > 0
&& getHeight() > 0
&& mEnabled) {
String newText = autoSplitText(this);
if (!TextUtils.isEmpty(newText)) {
setText(newText);
}
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}*/
public void setAutoText(CharSequence text) {
this.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
//String[] split = text.toString().split("\n");
setText(text);
setText(autoSplitText(AutoSplitTextView.this, text));
/*setText("");
boolean test=false;
if(text.toString().startsWith("累計送出1000鑽石的礼物")){
test=true;
System.out.println("新字測試");
}
for (String s : split) {
if(StringUtil.isEmpty(getText().toString())){
setText(autoSplitText(AutoSplitTextView.this,s));
}else{
setText(getText() + "\n" + autoSplitText(AutoSplitTextView.this, s));
if(test)
System.out.println(getText());
}
}*/
AutoSplitTextView.this.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}
private String autoSplitText(final TextView textView, CharSequence text) {
final String originalText = text.toString(); //原始文本
final Paint tvPaint = textView.getPaint();//获取TextView的Paint
final float tvWidth = textView.getWidth() - textView.getPaddingLeft() - textView.getPaddingRight(); //TextView的可用宽度
//将原始文本按行拆分
String[] originalTextLines = originalText.replaceAll("\r", "").split("\n");
StringBuilder newTextBuilder = new StringBuilder();
for (String originalTextLine : originalTextLines) {
//文本内容小于TextView宽度即不换行不作处理
if (tvPaint.measureText(originalTextLine) <= tvWidth) {
newTextBuilder.append(originalTextLine);
} else {
//如果整行宽度超过控件可用宽度,则按字符测量,在超过可用宽度的前一个字符处手动换行
float lineWidth = 0;
for (int i = 0; i != originalTextLine.length(); ++i) {
char charAt = originalTextLine.charAt(i);
lineWidth += tvPaint.measureText(String.valueOf(charAt));
if (lineWidth <= tvWidth) {
newTextBuilder.append(charAt);
} else {
//单行超过TextView可用宽度换行
newTextBuilder.append("\n");
lineWidth = 0;
--i;//该代码作用是将本轮循环回滚,在新的一行重新循环判断该字符
}
}
}
}
return newTextBuilder.toString();
}
}

View File

@@ -21,7 +21,7 @@
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginStart="23dp"
android:layout_marginTop="28dp"
android:layout_marginTop="48dp"
android:background="@drawable/bg_live_sud_game_top_new"
android:gravity="start|center_vertical">
@@ -69,10 +69,10 @@
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="98dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginTop="29dp"
android:layout_marginTop="49dp"
android:layout_marginEnd="20dp"
android:gravity="center_vertical">
@@ -147,7 +147,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginTop="75dp">
android:layout_marginTop="98dp">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/user_list"