Created
August 14, 2018 11:00
-
-
Save bitvale/b1b1a2eb8986e33aad6df29b6f720480 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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