diff --git a/app/src/main/java/com/teampome/pome/presentation/mypage/GridSpaceItemDecoration.kt b/app/src/main/java/com/teampome/pome/presentation/mypage/GridSpaceItemDecoration.kt new file mode 100644 index 00000000..f650fcab --- /dev/null +++ b/app/src/main/java/com/teampome/pome/presentation/mypage/GridSpaceItemDecoration.kt @@ -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() + } +} diff --git a/app/src/main/java/com/teampome/pome/presentation/mypage/MyPageFragment.kt b/app/src/main/java/com/teampome/pome/presentation/mypage/MyPageFragment.kt index 768fba87..8295874d 100644 --- a/app/src/main/java/com/teampome/pome/presentation/mypage/MyPageFragment.kt +++ b/app/src/main/java/com/teampome/pome/presentation/mypage/MyPageFragment.kt @@ -74,6 +74,8 @@ class MyPageFragment : BaseFragment(R.layout.fragment_myp // setHasFixedSize(true) layoutManager = manager adapter = marshmelloAdapter + addItemDecoration(GridSpaceItemDecoration(2)) } + } } \ No newline at end of file