refactor(layout): 优化布局尺寸计算逻辑并提取公共工具类
- 添加 SizeTool 工具类统一管理 Flexbox 布局尺寸计算 - 在 MasterScaleActivity 中使用 SizeTool 替代硬编码计算 - 在 SeasoningConfigFragment 中使用 SizeTool 重构尺寸计算 - 在 SlaveActivity 中应用统一的尺寸计算方法 - 更新 Seasoning18GridAdapter 和 Seasoning22GridAdapter 使用现代化布局参数设置 - 调整 fragment_seasoning_config.xml 中的边距和内边距数值 - 为布局文件添加 tools:itemCount 属性支持预览功能
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package com.shuwei.dish.match.utils
|
||||
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.utils.ext.dp
|
||||
|
||||
data class FlexLayoutSize(
|
||||
val smallSize: Int,
|
||||
val largeSize: Int,
|
||||
val rvHeight: Int
|
||||
)
|
||||
|
||||
object SizeTool {
|
||||
|
||||
fun getFlexLayoutSize(leftRightSpace: Int = 10.dp): FlexLayoutSize {
|
||||
// 上层:FlexboxLayoutManager,仿 MasterScaleActivity 中 Scale22VH 的布局方式
|
||||
// rvTop 高度 = 小格子尺寸 * 3行 + 3 * 间距,与 Scale22VH 保持一致
|
||||
val screenWidth = BaseApp.instance!!.resources.displayMetrics.widthPixels
|
||||
val usable = screenWidth - 8 * 4.dp - leftRightSpace
|
||||
val smallSize = usable / 9
|
||||
val largeSize = (usable - smallSize * 6) / 2
|
||||
val rvHeight = smallSize * 3 + 3 * 4.dp
|
||||
return FlexLayoutSize(smallSize, largeSize, rvHeight)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user