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"