Skip to content

Instantly share code, notes, and snippets.

@bitvale
Created August 14, 2018 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitvale/b1b1a2eb8986e33aad6df29b6f720480 to your computer and use it in GitHub Desktop.
Save bitvale/b1b1a2eb8986e33aad6df29b6f720480 to your computer and use it in GitHub Desktop.
private fun createCopyView(view: View): View {
val copy = copyViewImage(view)
// On preLollipop when we create a copy of card view's content its shadow is copied too
// and we do not need additional card view.
return (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CardView(view.context).apply {
cardElevation = resources.getDimension(R.dimen.card_elevation)
radius = resources.getDimension(R.dimen.card_corner_radius)
addView(copy)
}
} else {
copy
}).apply {
layoutParams = view.layoutParams
layoutParams.height = view.height
layoutParams.width = view.width
x = view.x
y = view.y + toolbar.height
}
}
private fun copyViewImage(view: View): ImageView {
val copy = ImageView(view.context)
val bitmap = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
view.draw(canvas)
copy.setImageBitmap(bitmap)
return copy
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment