fix: 返回按钮用 TouchDelegate 扩大点击区域

图标大小不变,触摸区域向下扩展 20dp、向右扩展 10dp
解决用户点偏到下方内容区的问题

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
dongliang
2026-05-07 16:30:34 +09:30
parent a41c8879e6
commit d5d1eeef89

View File

@@ -87,10 +87,19 @@ class TaskListFragment : BaseFragment<FragmentTaskListBinding>() {
val dialogContainer = requireActivity().findViewById<FrameLayout>(R.id.dialog_container) val dialogContainer = requireActivity().findViewById<FrameLayout>(R.id.dialog_container)
tipDialog = QuTipDialog(dialogContainer) tipDialog = QuTipDialog(dialogContainer)
// 返回按钮 // 返回按钮(扩大触摸区域,图标大小不变)
binding.btnBack.setOnClickListener { binding.btnBack.setOnClickListener {
findNavController().popBackStack() findNavController().popBackStack()
} }
// 用 TouchDelegate 向下和向右扩展点击区域
binding.btnBack.post {
val parent = binding.btnBack.parent as View
val rect = android.graphics.Rect()
binding.btnBack.getHitRect(rect)
rect.bottom += (20 * resources.displayMetrics.density).toInt()
rect.right += (10 * resources.displayMetrics.density).toInt()
parent.touchDelegate = android.view.TouchDelegate(rect, binding.btnBack)
}
// 左右滑手势(切换任务),上下滑留给内容滚动 // 左右滑手势(切换任务),上下滑留给内容滚动
gestureDetector = GestureDetector(requireContext(), object : GestureDetector.SimpleOnGestureListener() { gestureDetector = GestureDetector(requireContext(), object : GestureDetector.SimpleOnGestureListener() {