override fun setTranslationX(translationX: Float) {
super.setTranslationX(translationX)
updateVisible()
}
override fun setTranslationY(translationY: Float) {
super.setTranslationY(translationY)
updateVisible()
}
override fun setAlpha(alpha: Float) {
super.setAlpha(alpha)
updateVisible()
}
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
super.onLayout(changed, left, top, right, bottom)
updateVisible()
}
private fun updateVisible() {
visibility = if (
translationX >= measuredWidth || translationX <= -measuredWidth ||
translationY >= measuredHeight || translationY <= -measuredHeight ||
alpha == 0f
) {
INVISIBLE
} else {
VISIBLE
}
}