Skip to content

Instantly share code, notes, and snippets.

@EdNgulele
Created February 6, 2018 16:41
Show Gist options
  • Save EdNgulele/08094924ae06ea5345b4b9c4bc8952d2 to your computer and use it in GitHub Desktop.
Save EdNgulele/08094924ae06ea5345b4b9c4bc8952d2 to your computer and use it in GitHub Desktop.
class MainActivity : AppCompatActivity() {
private var selectedView: View? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
animateConstraints()
}
private fun animateConstraints() {
main_layout.setOnClickListener { defaultLayout() }
wonderwoman_img.setOnClickListener {
if (selectedView != wonderwoman_img) {
updateLayout(R.layout.activity_main_wonderwoman)
selectedView = wonderwoman_img
}
}
superman_img.setOnClickListener {
if (selectedView != superman_img) {
updateLayout(R.layout.activity_main_superman)
selectedView = superman_img
}
}
batman_img.setOnClickListener {
if (selectedView != batman_img) {
updateLayout(R.layout.activity_main_batman)
selectedView = batman_img
}
}
}
private fun defaultLayout() {
if (selectedView != null) {
updateLayout(R.layout.activity_main)
selectedView = null
}
}
private fun updateLayout(@LayoutRes id: Int) {
val constraintSet = ConstraintSet()
constraintSet.clone(this, id)
constraintSet.applyTo(main_layout)
val transition = ChangeBounds()
transition.interpolator = OvershootInterpolator()
TransitionManager.beginDelayedTransition(main_layout, transition)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment