fix(ui): 将表单布局从 FlexboxLayoutManager 改为 GridLayoutManager 两列,溯源码改为必填

This commit is contained in:
2026-05-26 21:34:38 +08:00
parent fabc4d780a
commit 37289d43f3
3 changed files with 7 additions and 22 deletions
@@ -12,7 +12,6 @@ import android.view.ViewGroup
import androidx.core.graphics.toColorInt
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.QuickViewHolder
import com.google.android.flexbox.FlexboxLayoutManager
import com.sw.inbound.R
import com.sw.inbound.databinding.ListItemFormFieldBinding
import com.sw.inbound.dialog.DropdownPopup
@@ -46,8 +45,6 @@ class FormFieldAdapter(
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
val binding = ListItemFormFieldBinding.inflate(LayoutInflater.from(context), parent, false)
// 设置每个 item 宽度占 FlexboxLayout 的 50%,实现两列布局
(binding.root.layoutParams as? FlexboxLayoutManager.LayoutParams)?.flexBasisPercent = 0.5f
return VH(binding)
}
@@ -179,11 +176,4 @@ class FormFieldAdapter(
}
}
/** RecyclerView 回收 ViewHolder 时移除 TextWatcher,防止复用错误 */
override fun onViewRecycled(holder: VH) {
super.onViewRecycled(holder)
val watcher = holder.binding.etInput.tag as? TextWatcher
watcher?.let { holder.binding.etInput.removeTextChangedListener(it) }
holder.binding.etInput.tag = null
}
}
@@ -9,9 +9,7 @@ import android.view.LayoutInflater
import android.view.View
import androidx.camera.view.PreviewView
import androidx.core.graphics.toColorInt
import com.google.android.flexbox.FlexDirection
import com.google.android.flexbox.FlexWrap
import com.google.android.flexbox.FlexboxLayoutManager
import androidx.recyclerview.widget.GridLayoutManager
import com.sw.inbound.GlobalData
import com.sw.inbound.activity.StoreActivity
import com.sw.inbound.adapter.FormFieldAdapter
@@ -94,7 +92,7 @@ class InboundGoodsStoreDialog(
DictType(id = id, value = zone.zoneName)
}
return mutableListOf(
FormField("溯源码", FieldType.TEXT, apiKey = "traceCode", value = goods.traceCode),
FormField("溯源码", FieldType.TEXT, apiKey = "traceCode", value = goods.traceCode, required = true, hint = "请录入溯源码"),
FormField("来源类型", FieldType.DROPDOWN, apiKey = "", options = listOf(
DictType("0", "手动录入"), DictType("1", "系统识别")
)),
@@ -127,7 +125,7 @@ class InboundGoodsStoreDialog(
DictType(id = id, value = zone.zoneName)
}
return mutableListOf(
FormField("溯源码", FieldType.TEXT, apiKey = "traceCode", value = goods.traceCode),
FormField("溯源码", FieldType.TEXT, apiKey = "traceCode", value = goods.traceCode, required = true, hint = "请录入溯源码"),
FormField("食材名称", FieldType.FIXED, apiKey = "ingredientName", required = true, value = goods.materName),
FormField("净材类型", FieldType.DROPDOWN, apiKey = "cleanType",
required = cleanTypeOptions.isNotEmpty(), hint = "请选择净材类型", options = cleanTypeOptions),
@@ -143,11 +141,7 @@ class InboundGoodsStoreDialog(
}
private fun setupRecyclerView() {
val flexboxLM = FlexboxLayoutManager(context).apply {
flexDirection = FlexDirection.ROW
flexWrap = FlexWrap.WRAP
}
binding.rvFormFields.layoutManager = flexboxLM
binding.rvFormFields.layoutManager = GridLayoutManager(context, 2)
binding.rvFormFields.adapter = FormFieldAdapter(storeActivity ?: context, fields)
}
@@ -4,7 +4,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingHorizontal="20dp"
android:paddingVertical="10dp">
<!-- 字段标签,必填项红色星号由 Adapter 通过 SpannableString 追加 -->
@@ -12,6 +11,7 @@
android:id="@+id/tvLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="12dp"
android:layout_marginBottom="6dp"
android:textColor="#FF141428"
android:textSize="20sp"
@@ -21,7 +21,8 @@
<!-- 输入区域容器,三种控件叠放,按 FieldType 切换 visibility -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="60dp">
android:layout_height="60dp"
android:layout_marginHorizontal="12dp">
<!-- TEXT / NUMBER / FIXED 类型:EditText -->
<EditText