Skip to content

Commit

Permalink
[fix] : #16 dpToPx Util화(PR반영)
Browse files Browse the repository at this point in the history
  • Loading branch information
SsongSik committed May 15, 2023
1 parent c6b1f0c commit 3a409c8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.teampome.pome.presentation.mypage

import android.content.Context
import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.teampome.pome.util.common.CommonUtil

class GridSpaceItemDecoration(private val spanCount: Int): RecyclerView.ItemDecoration() {
// 3, 20
Expand All @@ -17,17 +17,12 @@ class GridSpaceItemDecoration(private val spanCount: Int): RecyclerView.ItemDeco

val column = position % spanCount

val spaceInPx = dpToPx(parent.context, 5)
val spaceInPx = CommonUtil.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()
}
}
8 changes: 8 additions & 0 deletions app/src/main/java/com/teampome/pome/util/common/CommonUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -557,4 +557,12 @@ object CommonUtil {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(page))
context.startActivity(intent)
}

/*
* dp To Px 메소드
*/
fun dpToPx(context: Context, dp: Int): Int {
val density = context.resources.displayMetrics.density
return (dp * density + 0.5f).toInt()
}
}

0 comments on commit 3a409c8

Please sign in to comment.