fix(ui): 修复22格高宽比调整后列表高度显示不全
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,21 +15,24 @@ import com.shuwei.dish.match.R
|
|||||||
import com.shuwei.dish.match.databinding.ListItemScale22RowBinding
|
import com.shuwei.dish.match.databinding.ListItemScale22RowBinding
|
||||||
import com.shuwei.dish.match.scale.ScaleData
|
import com.shuwei.dish.match.scale.ScaleData
|
||||||
import com.shuwei.dish.match.scale.ScaleDeviceConfig
|
import com.shuwei.dish.match.scale.ScaleDeviceConfig
|
||||||
|
import com.shuwei.dish.match.utils.SizeTool
|
||||||
import com.shuwei.dish.match.utils.WeightUtil
|
import com.shuwei.dish.match.utils.WeightUtil
|
||||||
import com.shuwei.dish.match.utils.ext.dp
|
import com.shuwei.dish.match.utils.ext.dp
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 22格网格 Adapter,同时服务于调料配置页和主设备秤总览页。
|
* 22格网格 Adapter,同时服务于调料配置页和主设备秤总览页。
|
||||||
*
|
*
|
||||||
* @param largeSize 前4个大格子的尺寸(px)
|
* @param largeSize 前4个大格子的宽度(px)
|
||||||
* @param smallSize 其余小格子的尺寸(px)
|
* @param smallSize 其余小格子的宽度(px)
|
||||||
* @param showNameOnly true = 调料配置模式,仅显示 tvName,隐藏 tvWeight/tvState;
|
* @param cellAspectRatio 格子高宽比(height / width)
|
||||||
* false = 秤总览模式,三行全部显示
|
* @param showNameOnly true = 调料配置模式,仅显示 tvName,隐藏 tvWeight/tvState;
|
||||||
* @param showAddress true = 显示秤地址行(tvAddress),仅 MasterScaleActivity 使用
|
* false = 秤总览模式,三行全部显示
|
||||||
|
* @param showAddress true = 显示秤地址行(tvAddress),仅 MasterScaleActivity 使用
|
||||||
*/
|
*/
|
||||||
class Seasoning22GridAdapter(
|
class Seasoning22GridAdapter(
|
||||||
private val largeSize: Int,
|
private val largeSize: Int,
|
||||||
private val smallSize: Int,
|
private val smallSize: Int,
|
||||||
|
private val cellAspectRatio: Float = SizeTool.DEFAULT_CELL_ASPECT_RATIO,
|
||||||
private val showNameOnly: Boolean = false,
|
private val showNameOnly: Boolean = false,
|
||||||
private val showAddress: Boolean = false
|
private val showAddress: Boolean = false
|
||||||
) : BaseQuickAdapter<ScaleData, Seasoning22GridAdapter.VH>(mutableListOf()) {
|
) : BaseQuickAdapter<ScaleData, Seasoning22GridAdapter.VH>(mutableListOf()) {
|
||||||
@@ -51,13 +54,14 @@ class Seasoning22GridAdapter(
|
|||||||
|
|
||||||
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
|
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
|
||||||
val b = ListItemScale22RowBinding.inflate(LayoutInflater.from(context), parent, false)
|
val b = ListItemScale22RowBinding.inflate(LayoutInflater.from(context), parent, false)
|
||||||
val cellSize = if (viewType == 1) largeSize else smallSize
|
val cellWidth = if (viewType == 1) largeSize else smallSize
|
||||||
|
val cellHeight = (cellWidth * cellAspectRatio).toInt()
|
||||||
b.root.updateLayoutParams<FlexboxLayoutManager.LayoutParams> {
|
b.root.updateLayoutParams<FlexboxLayoutManager.LayoutParams> {
|
||||||
width = cellSize
|
width = cellWidth
|
||||||
height = cellSize
|
height = cellHeight
|
||||||
setMargins(2.dp, 2.dp, 2.dp, 2.dp)
|
setMargins(2.dp, 2.dp, 2.dp, 2.dp)
|
||||||
}
|
}
|
||||||
val baseSp = (cellSize / parent.resources.displayMetrics.density).toInt()
|
val baseSp = (cellWidth / parent.resources.displayMetrics.density).toInt()
|
||||||
b.tvAddress.textSize = (baseSp * 0.14f).coerceIn(8f, 12f)
|
b.tvAddress.textSize = (baseSp * 0.14f).coerceIn(8f, 12f)
|
||||||
b.tvName.textSize = (baseSp * 0.18f).coerceIn(10f, 16f)
|
b.tvName.textSize = (baseSp * 0.18f).coerceIn(10f, 16f)
|
||||||
b.tvWeight.textSize = (baseSp * 0.22f).coerceIn(12f, 20f)
|
b.tvWeight.textSize = (baseSp * 0.22f).coerceIn(12f, 20f)
|
||||||
|
|||||||
@@ -100,7 +100,11 @@ class SlaveActivity : BaseActivity() {
|
|||||||
flexWrap = FlexWrap.WRAP
|
flexWrap = FlexWrap.WRAP
|
||||||
alignItems = AlignItems.FLEX_START
|
alignItems = AlignItems.FLEX_START
|
||||||
}
|
}
|
||||||
scale22Adapter = Seasoning22GridAdapter(size.largeSize, size.smallSize, showNameOnly = false).also {
|
scale22Adapter = Seasoning22GridAdapter(
|
||||||
|
size.largeSize,
|
||||||
|
size.smallSize,
|
||||||
|
showNameOnly = false
|
||||||
|
).also {
|
||||||
it.onItemClick = { scale, _ -> showTareDialog(scale.address) }
|
it.onItemClick = { scale, _ -> showTareDialog(scale.address) }
|
||||||
}
|
}
|
||||||
binding.rvScaleList.adapter = scale22Adapter
|
binding.rvScaleList.adapter = scale22Adapter
|
||||||
@@ -320,7 +324,7 @@ class SlaveActivity : BaseActivity() {
|
|||||||
/** 重量增加阈值(克),超过此值才触发高亮 */
|
/** 重量增加阈值(克),超过此值才触发高亮 */
|
||||||
private const val WEIGHT_DELTA_THRESHOLD = 10.0
|
private const val WEIGHT_DELTA_THRESHOLD = 10.0
|
||||||
/** 高亮自动恢复时间(毫秒) */
|
/** 高亮自动恢复时间(毫秒) */
|
||||||
private const val HIGHLIGHT_DURATION_MS = 8_000L
|
private const val HIGHLIGHT_DURATION_MS = 5_000L
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class SeasoningConfigFragment : BaseFragment<FragmentSeasoningConfigBinding>() {
|
|||||||
private const val WEIGHT_DELTA_THRESHOLD = 10.0
|
private const val WEIGHT_DELTA_THRESHOLD = 10.0
|
||||||
|
|
||||||
/** 高亮自动恢复时间(毫秒) */
|
/** 高亮自动恢复时间(毫秒) */
|
||||||
private const val HIGHLIGHT_DURATION_MS = 8_000L
|
private const val HIGHLIGHT_DURATION_MS = 5_000L
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun inflateBinding(
|
override fun inflateBinding(
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.shuwei.dish.match.utils
|
|||||||
|
|
||||||
import com.shuwei.dish.match.base.BaseApp
|
import com.shuwei.dish.match.base.BaseApp
|
||||||
import com.shuwei.dish.match.utils.ext.dp
|
import com.shuwei.dish.match.utils.ext.dp
|
||||||
|
import kotlin.math.max
|
||||||
|
|
||||||
data class FlexLayoutSize(
|
data class FlexLayoutSize(
|
||||||
val smallSize: Int,
|
val smallSize: Int,
|
||||||
@@ -11,14 +12,28 @@ data class FlexLayoutSize(
|
|||||||
|
|
||||||
object SizeTool {
|
object SizeTool {
|
||||||
|
|
||||||
fun getFlexLayoutSize(leftRightSpace: Int = 10.dp): FlexLayoutSize {
|
const val DEFAULT_CELL_ASPECT_RATIO = 1.26f
|
||||||
|
|
||||||
|
fun getFlexLayoutSize(
|
||||||
|
leftRightSpace: Int,
|
||||||
|
cellAspectRatio: Float = DEFAULT_CELL_ASPECT_RATIO,
|
||||||
|
cellMargin: Int = 2.dp
|
||||||
|
): FlexLayoutSize {
|
||||||
// 上层:FlexboxLayoutManager,仿 MasterScaleActivity 中 Scale22VH 的布局方式
|
// 上层:FlexboxLayoutManager,仿 MasterScaleActivity 中 Scale22VH 的布局方式
|
||||||
// rvTop 高度 = 小格子尺寸 * 3行 + 3 * 间距,与 Scale22VH 保持一致
|
// rvTop 高度需覆盖:
|
||||||
|
// 1) 小格列(3行)总高度
|
||||||
|
// 2) 大格列(2行)总高度(考虑四舍五入误差)
|
||||||
val screenWidth = BaseApp.instance!!.resources.displayMetrics.widthPixels
|
val screenWidth = BaseApp.instance!!.resources.displayMetrics.widthPixels
|
||||||
val usable = screenWidth - 8 * 4.dp - leftRightSpace
|
val usable = screenWidth - 8 * 4.dp - leftRightSpace
|
||||||
val smallSize = usable / 9
|
val smallSize = usable / 9
|
||||||
val largeSize = (usable - smallSize * 6) / 2
|
val largeSize = (usable - smallSize * 6) / 2
|
||||||
val rvHeight = smallSize * 3 + 3 * 4.dp
|
val smallHeight = (smallSize * cellAspectRatio).toInt()
|
||||||
|
val largeHeight = (largeSize * cellAspectRatio).toInt()
|
||||||
|
|
||||||
|
val smallColumnHeight = smallHeight * 3 + cellMargin * 6
|
||||||
|
val largeColumnHeight = largeHeight * 2 + cellMargin * 4
|
||||||
|
val rvHeight = max(smallColumnHeight, largeColumnHeight)
|
||||||
|
|
||||||
return FlexLayoutSize(smallSize, largeSize, rvHeight)
|
return FlexLayoutSize(smallSize, largeSize, rvHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/llScaleContainer"
|
android:id="@+id/llScaleContainer"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="260dp"
|
android:layout_height="200dp"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:layout_marginTop="5dp"
|
android:layout_marginTop="5dp"
|
||||||
|
|||||||
Reference in New Issue
Block a user