Skip to content

Instantly share code, notes, and snippets.

@dadouf
Created December 11, 2020 10:44
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 dadouf/f8de9e5f7599a474ecc922b8cc7406a5 to your computer and use it in GitHub Desktop.
Save dadouf/f8de9e5f7599a474ecc922b8cc7406a5 to your computer and use it in GitHub Desktop.
class OverlayableImageView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
private val imageView: ImageView
private val sendButton: ImageButton
init {
imageView = ...
sendButton = ...
// android:animateLayoutChanges="true" for cross-fade
layoutTransition = LayoutTransition()
isActivated = false
}
override fun setActivated(activated: Boolean) {
val isChanging = activated != isActivated
super.setActivated(activated)
if (isChanging) {
// Switch between VISIBLE and INVISIBLE
sendButton.isInvisible = !activated
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment