From 373fa7fc80686bf35d0c40fcf44ade7bad5f76e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=99=A8?= Date: Thu, 8 Aug 2024 14:17:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E3=80=90=E5=85=89=E7=8E=AF=E5=8A=A9?= =?UTF-8?q?=E6=89=8B=E3=80=91=E6=B8=B8=E6=88=8F=E4=B8=93=E9=A2=98-?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E5=90=8D=E7=A7=B0=E6=98=BE=E7=A4=BA=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20https://jira.shanqu.cc/browse/GHZSCY-6463?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomGameHorizontalSlideAdapter.kt | 28 ++++++++++++++----- .../layout/game_horizontal_simple_item.xml | 2 +- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/gh/gamecenter/home/custom/adapter/CustomGameHorizontalSlideAdapter.kt b/app/src/main/java/com/gh/gamecenter/home/custom/adapter/CustomGameHorizontalSlideAdapter.kt index 2ef375ab81..9571d693ab 100644 --- a/app/src/main/java/com/gh/gamecenter/home/custom/adapter/CustomGameHorizontalSlideAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/home/custom/adapter/CustomGameHorizontalSlideAdapter.kt @@ -30,6 +30,13 @@ class CustomGameHorizontalSlideAdapter( private var isShowFirstLine = false private var isShowSecondLine = false + /** + * 当第一屏所有的 游戏名称都只有一行的长度时,recyclerView的整体高度会被固定 + * 后续就算出现了两行长度的游戏,标题栏仍然只能显示一行 + * 所以:这里需要提前计算,当列表中出现一个需要展示两行标题高度的游戏,则所有游戏标题设为两行 + * */ + private var hasTwoLinesName = false + private lateinit var _data: CustomSubjectItem private val subjectEntity: SubjectEntity @@ -39,18 +46,25 @@ class CustomGameHorizontalSlideAdapter( fun setData(data: CustomSubjectItem, exposureEventList: List?) { isShowFirstLine = false isShowSecondLine = false + hasTwoLinesName = false _data = data _exposureEventList = exposureEventList + data.data.data?.forEach { + if (!isShowFirstLine && it.assignRemark.firstLine.isNotEmpty()) { + isShowFirstLine = true + } + if (!isShowSecondLine && it.assignRemark.secondLine.isNotEmpty()) { + isShowSecondLine = true + } + val gameName = it.name ?: "" + if (!subjectEntity.showDownload && !hasTwoLinesName && gameName.length > 5) { + hasTwoLinesName = true + } + } submitList(data.data.data) } override fun getKey(t: GameEntity): String { - if (!isShowFirstLine && t.assignRemark.firstLine.isNotEmpty()) { - isShowFirstLine = true - } - if (!isShowSecondLine && t.assignRemark.secondLine.isNotEmpty()) { - isShowSecondLine = true - } return t.id } @@ -64,7 +78,7 @@ class CustomGameHorizontalSlideAdapter( holder.binding.root.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) holder.binding.simpleGameContainer.downloadBtn.goneIf(!subjectEntity.showDownload) - holder.binding.simpleGameContainer.gameName.maxLines = if (subjectEntity.showDownload) 1 else 2 + holder.binding.simpleGameContainer.gameName.setLines(if (hasTwoLinesName) 2 else 1) val gameEntity = getItem(position) holder.binding.simpleGameContainer.run { gameName.setTextColor(R.color.text_primary.toColor(root.context)) diff --git a/app/src/main/res/layout/game_horizontal_simple_item.xml b/app/src/main/res/layout/game_horizontal_simple_item.xml index 3d8e6f8e74..71679d13c5 100644 --- a/app/src/main/res/layout/game_horizontal_simple_item.xml +++ b/app/src/main/res/layout/game_horizontal_simple_item.xml @@ -18,7 +18,7 @@ android:layout_height="wrap_content" android:layout_marginTop="8dp" android:ellipsize="end" - android:gravity="center" + android:gravity="center_horizontal" android:lineSpacingExtra="4dp" android:maxLines="2" android:textColor="@color/text_primary"