fix(ui): 修复调料列表布局切换功能
- 将布局容器从 LinearLayout 改为 FrameLayout 以支持更好的定位控制 - 调整标题文本的尺寸和对齐方式,设置固定高度 50dp - 更新切换按钮的内边距并调整其在父容器中的位置 - 更改切换按钮的图标资源名称从 ic_switch_box 为 ic_layout_list - 优化布局切换逻辑,图标始终显示目标布局样式 - 在切换时动态更新按钮图标以反映当前布局模式
This commit is contained in:
@@ -12,6 +12,7 @@ import androidx.lifecycle.Lifecycle
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.lifecycle.repeatOnLifecycle
|
import androidx.lifecycle.repeatOnLifecycle
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
|
import com.shuwei.dish.match.R
|
||||||
import com.shuwei.dish.match.adapter.SeasoningWeightAdapter
|
import com.shuwei.dish.match.adapter.SeasoningWeightAdapter
|
||||||
import com.shuwei.dish.match.base.BaseActivity
|
import com.shuwei.dish.match.base.BaseActivity
|
||||||
import com.shuwei.dish.match.base.BaseApp
|
import com.shuwei.dish.match.base.BaseApp
|
||||||
@@ -310,12 +311,15 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun addViewListener() {
|
private fun addViewListener() {
|
||||||
// 切换调料列表布局:4 列卡片 ↔ 2 列水平
|
// 切换调料列表布局:4 列卡片 ↔ 2 列水平,图标始终显示"目标布局"样式
|
||||||
binding.ivSeasoningLayoutToggle.clickWithDebounce {
|
binding.ivSeasoningLayoutToggle.clickWithDebounce {
|
||||||
seasoningAdapter.isListMode = !seasoningAdapter.isListMode
|
seasoningAdapter.isListMode = !seasoningAdapter.isListMode
|
||||||
val spanCount = if (seasoningAdapter.isListMode) 2 else 4
|
val spanCount = if (seasoningAdapter.isListMode) 2 else 4
|
||||||
(binding.rvSeasoning.layoutManager as? GridLayoutManager)?.spanCount = spanCount
|
(binding.rvSeasoning.layoutManager as? GridLayoutManager)?.spanCount = spanCount
|
||||||
seasoningAdapter.notifyDataSetChanged()
|
seasoningAdapter.notifyDataSetChanged()
|
||||||
|
binding.ivSeasoningLayoutToggle.setImageResource(
|
||||||
|
if (seasoningAdapter.isListMode) R.drawable.ic_layout_grid else R.drawable.ic_layout_list
|
||||||
|
)
|
||||||
}
|
}
|
||||||
binding.btnCook.clickWithDebounce {
|
binding.btnCook.clickWithDebounce {
|
||||||
val content = getRemindSpannable("开始制作")
|
val content = getRemindSpannable("开始制作")
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
android:background="@drawable/shape_white_30_corners"
|
android:background="@drawable/shape_white_30_corners"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="22dp"
|
android:layout_marginStart="22dp"
|
||||||
@@ -26,11 +26,11 @@
|
|||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvTitle"
|
android:layout_width="wrap_content"
|
||||||
android:layout_width="0dp"
|
android:layout_height="50dp"
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:text="@string/seasoning"
|
android:text="@string/seasoning"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:layout_gravity="start"
|
||||||
android:textColor="@color/black666"
|
android:textColor="@color/black666"
|
||||||
android:textSize="28sp" />
|
android:textSize="28sp" />
|
||||||
|
|
||||||
@@ -38,12 +38,13 @@
|
|||||||
android:id="@+id/ivSeasoningLayoutToggle"
|
android:id="@+id/ivSeasoningLayoutToggle"
|
||||||
android:layout_width="50dp"
|
android:layout_width="50dp"
|
||||||
android:layout_height="50dp"
|
android:layout_height="50dp"
|
||||||
android:paddingVertical="8dp"
|
android:paddingVertical="2dp"
|
||||||
|
android:layout_gravity="end"
|
||||||
android:contentDescription="切换布局"
|
android:contentDescription="切换布局"
|
||||||
android:src="@drawable/ic_switch_box"
|
android:src="@drawable/ic_layout_list"
|
||||||
android:background="?android:attr/selectableItemBackgroundBorderless" />
|
android:background="?android:attr/selectableItemBackgroundBorderless" />
|
||||||
|
|
||||||
</LinearLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/rvSeasoning"
|
android:id="@+id/rvSeasoning"
|
||||||
|
|||||||
Reference in New Issue
Block a user