Skip to content

Instantly share code, notes, and snippets.

@BonusTrack02
Created November 15, 2023 16:34
Show Gist options
  • Save BonusTrack02/aed704c6c989a9345444758894c7acff to your computer and use it in GitHub Desktop.
Save BonusTrack02/aed704c6c989a9345444758894c7acff to your computer and use it in GitHub Desktop.
ViewPager2 set page margin including dp to px convert
binding.viewPager2.setPageTransformer(MarginPageTransformer(dpToPx(8).toInt()))
private fun dpToPx(dp: Int): Float {
val density = context.resources.displayMetrics.density
return round(dp * density)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment