Skip to content

Instantly share code, notes, and snippets.

@damianpetla
Created June 7, 2019 10:14
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 damianpetla/2b7740b6dbb9cf7ed9df7da88f6f27b4 to your computer and use it in GitHub Desktop.
Save damianpetla/2b7740b6dbb9cf7ed9df7da88f6f27b4 to your computer and use it in GitHub Desktop.
class AdItemHolder(item: View) : BaseHolder(item) {
private val adLabel = item.findViewById<View>(R.id.adlabel)
private val adContent = item.findViewById<View>(R.id.adcontent)
private val labelElevation = item.resources.getDimension(R.dimen.cardview_default_elevation)
init {
item.viewTreeObserver.addOnScrollChangedListener {
val offset = -item.top.toFloat()
adLabel.translationY = Math.max(offset, 0f)
adLabel.translationZ = if (offset < 0) labelElevation else 0f
adContent.translationY = offset
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment