From f99641ed3508cc4f437360b5315ef3b9c1336609 Mon Sep 17 00:00:00 2001
From: zlzw <583819556@qq.com>
Date: Fri, 26 Jan 2024 13:42:38 +0800
Subject: [PATCH] =?UTF-8?q?=E6=88=98=E4=BB=A4=E7=9B=B8=E5=85=B3UI=E8=B0=83?=
=?UTF-8?q?=E6=95=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../common/views/AutoSplitTextView.java | 105 +++
.../src/main/res/layout/activity_sud_game.xml | 8 +-
.../main/activity/BattlePassActivity.java | 2 +-
.../adapter/BattlePassMissionAdapter.java | 14 +-
.../main/res/layout/activity_battlepass.xml | 2 +-
.../layout/fragment_battlepass_mission.xml | 2 +-
.../res/layout/fragment_battlepass_reward.xml | 8 +-
.../res/layout/item_battlepass_exchange.xml | 19 +-
.../item_battlepass_mission_type_mission.xml | 78 ++-
.../item_battlepass_mission_type_title.xml | 4 +-
.../item_battlepass_reward_type_top.xml | 637 +++++++++---------
.../main/res/layout/view_battlepass_user.xml | 1 -
main/src/main/res/layout/view_homemain.xml | 8 +-
13 files changed, 521 insertions(+), 367 deletions(-)
create mode 100644 common/src/main/java/com/yunbao/common/views/AutoSplitTextView.java
diff --git a/common/src/main/java/com/yunbao/common/views/AutoSplitTextView.java b/common/src/main/java/com/yunbao/common/views/AutoSplitTextView.java
new file mode 100644
index 000000000..c85e10a2e
--- /dev/null
+++ b/common/src/main/java/com/yunbao/common/views/AutoSplitTextView.java
@@ -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();
+ }
+}
diff --git a/common/src/main/res/layout/activity_sud_game.xml b/common/src/main/res/layout/activity_sud_game.xml
index cae4a3e06..7688f57b5 100644
--- a/common/src/main/res/layout/activity_sud_game.xml
+++ b/common/src/main/res/layout/activity_sud_game.xml
@@ -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 @@
@@ -147,7 +147,7 @@
+ android:layout_marginTop="98dp">
0) {
- title.setText(String.format("%s(%s/%s)",
+ String format = String.format("%s(%s/%s)",
task.getNameText(),
task.getUserTaskSuccess(),
- task.getTaskSuccess())
- );
+ task.getTaskSuccess());
+ title.setAutoText(format);
} else {
title.setText(task.getNameText());
}
diff --git a/main/src/main/res/layout/activity_battlepass.xml b/main/src/main/res/layout/activity_battlepass.xml
index 19e677e67..4639d1bc0 100644
--- a/main/src/main/res/layout/activity_battlepass.xml
+++ b/main/src/main/res/layout/activity_battlepass.xml
@@ -21,7 +21,7 @@
android:layout_height="0dp"
android:layout_marginStart="15dp"
android:orientation="vertical"
- android:layout_marginTop="30dp"
+ android:layout_marginTop="45dp"
android:layout_marginEnd="15dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
diff --git a/main/src/main/res/layout/fragment_battlepass_mission.xml b/main/src/main/res/layout/fragment_battlepass_mission.xml
index 592ba7037..56dcf0b92 100644
--- a/main/src/main/res/layout/fragment_battlepass_mission.xml
+++ b/main/src/main/res/layout/fragment_battlepass_mission.xml
@@ -6,7 +6,7 @@
android:layout_height="match_parent">
@@ -18,10 +19,12 @@
android:id="@+id/tab_1"
android:layout_width="90dp"
android:layout_height="40dp"
+ android:layout_weight="1"
android:src="@mipmap/ic_reward_tab_normal" />
@@ -30,6 +33,7 @@
android:id="@+id/tab_3"
android:layout_width="90dp"
android:layout_height="40dp"
+ android:layout_weight="1"
android:src="@mipmap/ic_reward_tab_ultimate_unselect" />
@@ -38,8 +42,8 @@
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
- android:layout_marginEnd="10dp"
android:layout_marginStart="5dp"
+ android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:layout_weight="1"
tools:listitem="@layout/item_battlepass_reward_type_top" />
diff --git a/main/src/main/res/layout/item_battlepass_exchange.xml b/main/src/main/res/layout/item_battlepass_exchange.xml
index 6f9e9675d..cecb14230 100644
--- a/main/src/main/res/layout/item_battlepass_exchange.xml
+++ b/main/src/main/res/layout/item_battlepass_exchange.xml
@@ -5,15 +5,13 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="100dp"
android:gravity="center"
- android:layout_height="200dp"
- android:layout_marginBottom="10dp"
- android:layout_marginTop="10dp">
+ android:layout_height="165dp"
+ android:layout_marginBottom="10dp">
-
-
-
+ app:layout_constraintTop_toTopOf="parent">
+
+
+
+
+
+
\ No newline at end of file
diff --git a/main/src/main/res/layout/view_battlepass_user.xml b/main/src/main/res/layout/view_battlepass_user.xml
index 16a99bcf4..b5f1ca9f3 100644
--- a/main/src/main/res/layout/view_battlepass_user.xml
+++ b/main/src/main/res/layout/view_battlepass_user.xml
@@ -116,7 +116,6 @@
android:layout_height="wrap_content">
+ tools:visibility="gone" />
+ tools:visibility="gone" />
+ android:layout_marginRight="25dp"
+ />