Skip to content

Instantly share code, notes, and snippets.

@EmmanuelGuther
Created November 15, 2018 14:09
Show Gist options
  • Select an option

  • Save EmmanuelGuther/d64944d1bb643fd9405a3eeea9f0c839 to your computer and use it in GitHub Desktop.

Select an option

Save EmmanuelGuther/d64944d1bb643fd9405a3eeea9f0c839 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)
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main)
selectedView = null
left.setOnClickListener {
if (selectedView != left) {
updateConstraints(R.layout.activity_main_left)
selectedView = left
} else {
toDefault()
}
}
middle.setOnClickListener {
if (selectedView != middle) {
updateConstraints(R.layout.activity_main_middle)
selectedView = middle
} else {
toDefault()
}
}
right.setOnClickListener {
if (selectedView != right) {
updateConstraints(R.layout.activity_main_right)
selectedView = right
} else {
toDefault()
}
}
root.setOnClickListener {
toDefault()
}
}
private fun toDefault() {
if (selectedView != null) {
updateConstraints(R.layout.activity_main)
selectedView = null
}
}
fun updateConstraints(@LayoutRes id: Int) {
val newConstraintSet = ConstraintSet()
newConstraintSet.clone(this, id)
newConstraintSet.applyTo(root)
val transition = ChangeBounds()
transition.interpolator = OvershootInterpolator()
TransitionManager.beginDelayedTransition(root, transition)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment