Skip to content

Commit

Permalink
[feat] : #16 마시멜로 itemDecoration 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
SsongSik committed May 15, 2023
1 parent 4aca2df commit c6b1f0c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.teampome.pome.presentation.mypage

import android.content.Context
import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView

class GridSpaceItemDecoration(private val spanCount: Int): RecyclerView.ItemDecoration() {
// 3, 20
override fun getItemOffsets(
outRect: Rect,
view: View,
parent: RecyclerView,
state: RecyclerView.State
) {
val position = parent.getChildAdapterPosition(view)

val column = position % spanCount

val spaceInPx = dpToPx(parent.context, 5)

if (column == 0) {
outRect.right = spaceInPx
} else if (column == 1) {
outRect.left = spaceInPx
}
}

private fun dpToPx(context: Context, dp: Int): Int {
val density = context.resources.displayMetrics.density
return (dp * density + 0.5f).toInt()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class MyPageFragment : BaseFragment<FragmentMypageBinding>(R.layout.fragment_myp
// setHasFixedSize(true)
layoutManager = manager
adapter = marshmelloAdapter
addItemDecoration(GridSpaceItemDecoration(2))
}

}
}

0 comments on commit c6b1f0c

Please sign in to comment.