File tree Expand file tree Collapse file tree 1 file changed +8
-10
lines changed
app/src/main/java/com/hoc/pagination_mvi/ui/main Expand file tree Collapse file tree 1 file changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -58,18 +58,19 @@ class MainFragment : Fragment() {
5858 private fun setupView () {
5959 recycler.run {
6060 setHasFixedSize(true )
61+ adapter = this @MainFragment.adapter
62+
6163 layoutManager = GridLayoutManager (context, maxSpanCount).apply {
6264 spanSizeLookup = object : GridLayoutManager .SpanSizeLookup () {
6365 override fun getSpanSize (position : Int ): Int {
64- return if (this @MainFragment. adapter.getItemViewType(position) == R .layout.recycler_item_photo) {
66+ return if (adapter!! .getItemViewType(position) == R .layout.recycler_item_photo) {
6567 1
6668 } else {
67- 2
69+ maxSpanCount
6870 }
6971 }
7072 }
7173 }
72- adapter = this @MainFragment.adapter
7374
7475 val space = 8
7576 addItemDecoration(object : RecyclerView .ItemDecoration () {
@@ -92,13 +93,10 @@ class MainFragment : Fragment() {
9293 R .layout.recycler_item_photo -> {
9394 outRect.top = space
9495 outRect.bottom = 0
95- if (position % 2 != 0 ) {
96- outRect.left = space
97- outRect.right = space / 2
98- } else {
99- outRect.left = space / 2
100- outRect.right = space
101- }
96+
97+ val column = position % maxSpanCount - 1
98+ outRect.right = space * (column + 1 ) / maxSpanCount
99+ outRect.left = space - space * column / maxSpanCount
102100 }
103101 R .layout.recycler_item_placeholder -> {
104102 outRect.left = space
You can’t perform that action at this time.
0 commit comments