横屏分割线改纯XML结构化对齐(match_parent继承时间行高),删除运行时高度代码,版本 1.9
This commit is contained in:
13
CHANGELOG.md
13
CHANGELOG.md
@@ -1,5 +1,18 @@
|
||||
# 变更记录
|
||||
|
||||
## 2026-11-30 · 横屏分割线改纯XML结构化对齐(match_parent继承时间行高),删除运行时高度代码,版本 1.9
|
||||
|
||||
- 同步源码更新 4 个文件(新增/修改 4,删除 0)。
|
||||
|
||||
## 2026-11-30 · 横屏分割线结构化对齐(v1.9)
|
||||
|
||||
- 起因:分割线高度连续两版用「运行时改 LayoutParams」(View.post / fontMetrics 计算后 requestLayout)都在锁屏/悬浮窗链路上失效,线不显示。
|
||||
- 根因:运行时改高度依赖布局系统对特殊窗口的重新布局,链路不可靠。
|
||||
- 方案:改为纯 XML 结构约束——横屏布局重排为上下两行:上行「倒计时 | 分割线 | 时钟」同行排布,分割线 layout_height=match_parent 直接继承行高(行高即 130sp 时间文字高度);下行「任务名 | 占位 | 日期」与上行两栏逐列对齐。删除 Activity 与 LockOverlay 里的 syncDivider 代码,零运行时逻辑。
|
||||
- 改动文件:layout-land/activity_lock_screen.xml、LockScreenActivity.kt、LockOverlay.kt、build.gradle.kts、build.sh、SettingsFragment.kt。
|
||||
- 本地验证:构建通过,aapt 确认 versionCode 43 / versionName 1.9,签名 SHA-256 7bcbd511…cc8c83 不变。
|
||||
- 升级说明:直接覆盖安装,无数据迁移。
|
||||
|
||||
## 2026-11-29 · 分割线算法化/删除线居中/置顶图标对齐(v1.8)
|
||||
|
||||
- 横屏分割线消失修复:上一版用 View.post 等布局完成后取 height 再赋值,在锁屏/悬浮窗链路上时机不稳导致线整条消失;改为直接由 paint.fontMetrics 算出文字实际高度(includeFontPadding=false 时 TextView 高度即 ascent..descent 跨度),零时序依赖、立即生效(Activity 与悬浮窗两链路同步)
|
||||
|
||||
@@ -137,30 +137,11 @@ object LockOverlay {
|
||||
view.findViewById<TextView>(R.id.tvLockClock)?.text = clockFmt.format(cal.time)
|
||||
view.findViewById<TextView>(R.id.tvLockCountdown)?.text = Dates.clock(now)
|
||||
|
||||
syncDivider(view)
|
||||
|
||||
val task = if (TimerCore.taskId > 0) Store.task(TimerCore.taskId)?.title else null
|
||||
view.findViewById<TextView>(R.id.tvLockTask)?.text =
|
||||
task?.takeIf { it.isNotBlank() } ?: view.context.getString(R.string.notif_no_task)
|
||||
}
|
||||
|
||||
/**
|
||||
* 横屏排版里的分割线只分割两块大时间:高度直接由 paint.fontMetrics 算出
|
||||
* (includeFontPadding=false 时 TextView 高度就是 ascent..descent 跨度),
|
||||
* 不依赖布局完成时机——上一版 View.post 在悬浮窗链路上时序不稳导致线消失。
|
||||
* 竖屏布局没有这个控件,查找结果为 null 直接跳过。
|
||||
*/
|
||||
private fun syncDivider(view: View) {
|
||||
val divider = view.findViewById<View>(R.id.lockDivider) ?: return
|
||||
val countdown = view.findViewById<TextView>(R.id.tvLockCountdown) ?: return
|
||||
val fm = countdown.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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -539,6 +539,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val VERSION = "1.8"
|
||||
const val VERSION = "1.9"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
锁屏全屏倒计时·横屏专属排版(区别于竖屏的纯纵向堆叠):
|
||||
左右对称分栏 —— 左侧倒计时(大)+ 任务名,右侧时钟(大)+ 日期星期,
|
||||
两侧主字号统一 96sp,视觉左右对应;无「工作中/休息中」提示。
|
||||
上行是主行:倒计时 | 分割线 | 时钟,三者在同一行内,
|
||||
分割线高度用 match_parent 直接继承行高——行高由两侧 130sp 大时间撑起,
|
||||
所以线高天然与时间文字一致,纯 XML 结构保证,不依赖任何运行时代码
|
||||
(此前两版运行时改高度的方案在锁屏/悬浮窗链路上都失效了)。
|
||||
下行是副行:任务名 | 占位 | 日期星期,与上行两栏逐列对齐。
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/lockRoot"
|
||||
@@ -11,10 +14,15 @@
|
||||
android:background="@android:color/black"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:gravity="center_vertical"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- 上行:倒计时 | 分割线 | 时钟(分割线高度=本行高度=时间文字高度) -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<!-- 左:倒计时 + 任务名 -->
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -30,27 +38,14 @@
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="130sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvLockTask"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:ellipsize="end"
|
||||
android:maxWidth="320dp"
|
||||
android:maxLines="1"
|
||||
android:textColor="#99FFFFFF"
|
||||
android:textSize="15sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 中:细分隔线(只分割两块大时间,高度运行时对齐倒计时文字的实际高度) -->
|
||||
<View
|
||||
android:id="@+id/lockDivider"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="180dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#26FFFFFF" />
|
||||
|
||||
<!-- 右:时钟(大)+ 日期星期在时钟下面 -->
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -66,14 +61,52 @@
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="130sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 下行:任务名 | 占位(与分割线同宽,保持两栏对齐) | 日期星期 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvLockTask"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxWidth="320dp"
|
||||
android:maxLines="1"
|
||||
android:textColor="#99FFFFFF"
|
||||
android:textSize="15sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvLockDate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:textColor="#99FFFFFF"
|
||||
android:textSize="15sp" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
Reference in New Issue
Block a user