Skip to content

Commit

Permalink
add itemSpace BindingAdapter for dp
Browse files Browse the repository at this point in the history
  • Loading branch information
sjjeong committed Nov 24, 2019
1 parent aa6e9d9 commit 4b20230
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,19 @@ fun RecyclerView.setItemSpace(space: Float) {
}
val spacePixel = context.resources.displayMetrics.density * space
addItemDecoration(DinoSpaceItemDecoration(spacePixel.toInt()))
}

@BindingAdapter("dino_itemSpace")
fun RecyclerView.setItemSpace(space: String) {
if (!space.contains("dp")) {
return
}
val dpSpace = try {
space.dropLast(2).toFloat()
} catch (e: Exception) {
e.printStackTrace()
0f
}
val spacePixel = context.resources.displayMetrics.density * dpSpace
setItemSpace(spacePixel)
}

0 comments on commit 4b20230

Please sign in to comment.