소스 검색

优化锁定站的spancount算法设置,优化其显示效果

Frankensteinly 9 달 전
부모
커밋
2368ed377c
1개의 변경된 파일6개의 추가작업 그리고 2개의 파일을 삭제
  1. 6 2
      app/src/main/java/com/grkj/iscs/view/fragment/StepFragment.kt

+ 6 - 2
app/src/main/java/com/grkj/iscs/view/fragment/StepFragment.kt

@@ -19,6 +19,8 @@ import com.grkj.iscs.view.iview.IStepView
 import com.grkj.iscs.view.presenter.StepPresenter
 import com.zhy.adapter.recyclerview.CommonAdapter
 import com.zhy.adapter.recyclerview.base.ViewHolder
+import kotlin.math.ceil
+import kotlin.math.sqrt
 
 /**
  * 作业票执行步骤页 - 八大步骤
@@ -162,8 +164,10 @@ class StepFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> Uni
                 mLotoList.clear()
                 mLotoList.addAll(it)
             } ?: mLotoList.clear()
-            (mBinding?.rvLoto?.layoutManager as GridLayoutManager).spanCount =
-                if (mLotoList.size == 0) 3 else mLotoList.size / 3 + if (mLotoList.size % 3 == 0) 0 else 1
+
+            val spanCount = (ceil(sqrt(mLotoList.size.toFloat())) - 1).toInt()
+            (mBinding?.rvLoto?.layoutManager as GridLayoutManager).spanCount = spanCount
+
             mBinding?.rvLoto?.adapter?.notifyDataSetChanged()
         }
     }