横屏分割线改纯XML结构化对齐(match_parent继承时间行高),删除运行时高度代码,版本 1.9

This commit is contained in:
XIGE
2026-11-30 00:28:57 +08:00
parent 7762e463d6
commit 5b58596727
5 changed files with 97 additions and 89 deletions

View File

@@ -156,29 +156,10 @@ class LockScreenActivity : AppCompatActivity() {
tvClock.text = clockFmt.format(cal.time)
tvCountdown.text = Dates.clock(now)
syncDivider()
val task = if (TimerCore.taskId > 0) Store.task(TimerCore.taskId)?.title else null
tvTask.text = task?.takeIf { it.isNotBlank() } ?: getString(R.string.notif_no_task)
}
/**
* 横屏排版里的分割线只分割两块大时间,高度对齐倒计时文字的实际渲染高度。
* 上一版用 View.post 等布局完成后再取 height,实测在悬浮窗/锁屏链路上
* 时机不稳导致分割线整条消失;这里改为直接由 paint.fontMetrics 算出
* (includeFontPadding=false 时 TextView 高度就是 ascent..descent 跨度),
* 零时序依赖、立即生效。竖屏布局没有这个控件,查找结果为 null 直接跳过。
*/
private fun syncDivider() {
val divider = findViewById<View>(R.id.lockDivider) ?: return
val fm = tvCountdown.paint.fontMetrics
val h = (fm.descent - fm.ascent).toInt()
if (h > 0 && divider.layoutParams != null && divider.layoutParams.height != h) {
divider.layoutParams.height = h
divider.requestLayout()
}
}
/** Calendar 的 DAY_OF_WEEK(周日=1)转成 weekdayShort 的下标(周一=0 … 周日=6) */
private fun weekdayIndex(cal: Calendar): Int = (cal.get(Calendar.DAY_OF_WEEK) + 5) % 7
}